]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-undo.ts
39da824f37eeb3310d317166a24f886fe0e812a5
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-undo.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityFollow, ActivityUndo } from '../../../../shared/models/activitypub/activity'
3 import { AccountInstance } from '../../../models'
4 import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
5 import { unicastTo } from './misc'
6 import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl } from '../../../helpers/activitypub'
7 import { followActivityData } from './send-follow'
8
9 async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) {
10 const me = accountFollow.AccountFollower
11 const following = accountFollow.AccountFollowing
12
13 const followUrl = getAccountFollowActivityPubUrl(accountFollow)
14 const undoUrl = getUndoActivityPubUrl(followUrl)
15
16 const object = await followActivityData(followUrl, me, following)
17 const data = await undoActivityData(undoUrl, me, object)
18
19 return unicastTo(data, me, following.inboxUrl, t)
20 }
21
22 // ---------------------------------------------------------------------------
23
24 export {
25 sendUndoFollow
26 }
27
28 // ---------------------------------------------------------------------------
29
30 async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow) {
31 const activity: ActivityUndo = {
32 type: 'Undo',
33 id: url,
34 actor: byAccount.url,
35 object
36 }
37
38 return activity
39 }