1 import { Transaction } from 'sequelize'
8 } from '../../../../shared/models/activitypub'
9 import { AccountModel } from '../../../models/account/account'
10 import { AccountFollowModel } from '../../../models/account/account-follow'
11 import { VideoModel } from '../../../models/video/video'
12 import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
15 getAccountsInvolvedInVideo,
17 getObjectFollowersAudience,
18 getOriginVideoAudience,
21 import { createActivityData, createDislikeActivityData } from './send-create'
22 import { followActivityData } from './send-follow'
23 import { likeActivityData } from './send-like'
25 async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) {
26 const me = accountFollow.AccountFollower
27 const following = accountFollow.AccountFollowing
29 const followUrl = getAccountFollowActivityPubUrl(accountFollow)
30 const undoUrl = getUndoActivityPubUrl(followUrl)
32 const object = followActivityData(followUrl, me, following)
33 const data = await undoActivityData(undoUrl, me, object, t)
35 return unicastTo(data, me, following.inboxUrl, t)
38 async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
39 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
40 const undoUrl = getUndoActivityPubUrl(likeUrl)
42 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
43 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
44 const object = await likeActivityData(likeUrl, byAccount, video, t)
45 const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
47 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
50 async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
51 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
52 const undoUrl = getUndoActivityPubUrl(likeUrl)
54 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
55 const audience = getObjectFollowersAudience(toAccountsFollowers)
56 const object = await likeActivityData(likeUrl, byAccount, video, t)
57 const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
59 const followersException = [ byAccount ]
60 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
63 async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
64 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
65 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
67 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
68 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
69 const dislikeActivity = createDislikeActivityData(byAccount, video)
70 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
72 const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
74 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
77 async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
78 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
79 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
81 const dislikeActivity = createDislikeActivityData(byAccount, video)
82 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
84 const data = await undoActivityData(undoUrl, byAccount, object, t)
86 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
88 const followersException = [ byAccount ]
89 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
92 // ---------------------------------------------------------------------------
97 sendUndoLikeToVideoFollowers,
98 sendUndoDislikeToOrigin,
99 sendUndoDislikeToVideoFollowers
102 // ---------------------------------------------------------------------------
104 async function undoActivityData (
106 byAccount: AccountModel,
107 object: ActivityFollow | ActivityLike | ActivityCreate,
109 audience?: ActivityAudience
110 ): Promise<ActivityUndo> {
112 audience = await getAudience(byAccount, t)
118 actor: byAccount.url,