1 import { Transaction } from 'sequelize'
2 import { ActivityCreate } from '../../../../shared/models/activitypub/activity'
3 import { getServerAccount } from '../../../helpers/utils'
4 import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
5 import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface'
6 import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
9 getAccountsToForwardVideoAction,
11 getOriginVideoAudience,
12 getVideoFollowersAudience,
16 async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
17 const byAccount = videoChannel.Account
19 const videoChannelObject = videoChannel.toActivityPubObject()
20 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject)
22 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
25 async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) {
26 const url = getVideoAbuseActivityPubUrl(videoAbuse)
28 const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
29 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience)
31 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
34 async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
35 const url = getVideoViewActivityPubUrl(byAccount, video)
36 const viewActivity = createViewActivityData(byAccount, video)
38 const audience = getOriginVideoAudience(video)
39 const data = await createActivityData(url, byAccount, viewActivity, audience)
41 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
44 async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
45 const url = getVideoViewActivityPubUrl(byAccount, video)
46 const viewActivity = createViewActivityData(byAccount, video)
48 const audience = getVideoFollowersAudience(video)
49 const data = await createActivityData(url, byAccount, viewActivity, audience)
51 const serverAccount = await getServerAccount()
52 const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
54 const followersException = [ byAccount ]
55 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
58 async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
59 const url = getVideoDislikeActivityPubUrl(byAccount, video)
60 const dislikeActivity = createDislikeActivityData(byAccount, video)
62 const audience = getOriginVideoAudience(video)
63 const data = await createActivityData(url, byAccount, dislikeActivity, audience)
65 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
68 async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
69 const url = getVideoDislikeActivityPubUrl(byAccount, video)
70 const dislikeActivity = createDislikeActivityData(byAccount, video)
72 const audience = getVideoFollowersAudience(video)
73 const data = await createActivityData(url, byAccount, dislikeActivity, audience)
75 const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
76 const serverAccount = await getServerAccount()
78 const followersException = [ byAccount ]
79 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
82 async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: { to: string[], cc: string[] }) {
84 audience = await getAudience(byAccount)
87 const activity: ActivityCreate = {
99 function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) {
102 actor: byAccount.url,
109 // ---------------------------------------------------------------------------
112 sendCreateVideoChannel,
115 sendCreateViewToOrigin,
116 sendCreateViewToVideoFollowers,
117 sendCreateDislikeToOrigin,
118 sendCreateDislikeToVideoFollowers,
119 createDislikeActivityData
122 // ---------------------------------------------------------------------------
124 function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) {
127 actor: byAccount.url,