1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
3 import { getServerAccount } from '../../../helpers'
4 import { AccountModel } from '../../../models/account/account'
5 import { VideoModel } from '../../../models/video/video'
6 import { VideoAbuseModel } from '../../../models/video/video-abuse'
7 import { VideoChannelModel } from '../../../models/video/video-channel'
8 import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
11 getAccountsInvolvedInVideo,
13 getObjectFollowersAudience,
14 getOriginVideoAudience,
18 async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
19 const byAccount = videoChannel.Account
21 const videoChannelObject = videoChannel.toActivityPubObject()
22 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t)
24 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
27 async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) {
28 const url = getVideoAbuseActivityPubUrl(videoAbuse)
30 const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
31 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience)
33 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
36 async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
37 const url = getVideoViewActivityPubUrl(byAccount, video)
38 const viewActivity = createViewActivityData(byAccount, video)
40 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
41 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
42 const data = await createActivityData(url, byAccount, viewActivity, t, audience)
44 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
47 async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
48 const url = getVideoViewActivityPubUrl(byAccount, video)
49 const viewActivity = createViewActivityData(byAccount, video)
51 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
52 const audience = getObjectFollowersAudience(accountsToForwardView)
53 const data = await createActivityData(url, byAccount, viewActivity, t, audience)
55 // Use the server account to send the view, because it could be an unregistered account
56 const serverAccount = await getServerAccount()
57 const followersException = [ byAccount ]
58 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
61 async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
62 const url = getVideoDislikeActivityPubUrl(byAccount, video)
63 const dislikeActivity = createDislikeActivityData(byAccount, video)
65 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
66 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
67 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
69 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
72 async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
73 const url = getVideoDislikeActivityPubUrl(byAccount, video)
74 const dislikeActivity = createDislikeActivityData(byAccount, video)
76 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
77 const audience = getObjectFollowersAudience(accountsToForwardView)
78 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
80 const followersException = [ byAccount ]
81 return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException)
84 async function createActivityData (
86 byAccount: AccountModel,
89 audience?: ActivityAudience
90 ): Promise<ActivityCreate> {
92 audience = await getAudience(byAccount, t)
105 function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) {
108 actor: byAccount.url,
113 // ---------------------------------------------------------------------------
116 sendCreateVideoChannel,
119 sendCreateViewToOrigin,
120 sendCreateViewToVideoFollowers,
121 sendCreateDislikeToOrigin,
122 sendCreateDislikeToVideoFollowers,
123 createDislikeActivityData
126 // ---------------------------------------------------------------------------
128 function createViewActivityData (byAccount: AccountModel, video: VideoModel) {
131 actor: byAccount.url,