aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-create.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r--server/lib/activitypub/send/send-create.ts62
1 files changed, 50 insertions, 12 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index e5fb212b7..6afe67ee6 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -1,11 +1,17 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityCreate } from '../../../../shared/models/activitypub/activity' 2import { ActivityCreate } from '../../../../shared/models/activitypub/activity'
3import { getServerAccount } from '../../../helpers/utils'
3import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' 4import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
4import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' 5import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface'
5import { broadcastToFollowers, getAudience, unicastTo } from './misc' 6import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
6import { getVideoAbuseActivityPubUrl, getVideoViewActivityPubUrl } from '../url' 7import {
7import { getServerAccount } from '../../../helpers/utils' 8 broadcastToFollowers,
8import { database as db } from '../../../initializers' 9 getAccountsToForwardVideoAction,
10 getAudience,
11 getOriginVideoAudience,
12 getVideoFollowersAudience,
13 unicastTo
14} from './misc'
9 15
10async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { 16async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
11 const byAccount = videoChannel.Account 17 const byAccount = videoChannel.Account
@@ -29,7 +35,7 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI
29 const url = getVideoViewActivityPubUrl(byAccount, video) 35 const url = getVideoViewActivityPubUrl(byAccount, video)
30 const viewActivity = createViewActivityData(byAccount, video) 36 const viewActivity = createViewActivityData(byAccount, video)
31 37
32 const audience = { to: [ video.VideoChannel.Account.url ], cc: [ video.VideoChannel.Account.url + '/followers' ] } 38 const audience = getOriginVideoAudience(video)
33 const data = await createActivityData(url, byAccount, viewActivity, audience) 39 const data = await createActivityData(url, byAccount, viewActivity, audience)
34 40
35 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 41 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
@@ -39,16 +45,35 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video
39 const url = getVideoViewActivityPubUrl(byAccount, video) 45 const url = getVideoViewActivityPubUrl(byAccount, video)
40 const viewActivity = createViewActivityData(byAccount, video) 46 const viewActivity = createViewActivityData(byAccount, video)
41 47
42 const audience = { to: [ video.VideoChannel.Account.url + '/followers' ], cc: [] } 48 const audience = getVideoFollowersAudience(video)
43 const data = await createActivityData(url, byAccount, viewActivity, audience) 49 const data = await createActivityData(url, byAccount, viewActivity, audience)
44 50
45 const serverAccount = await getServerAccount() 51 const serverAccount = await getServerAccount()
46 const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id) 52 const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
47 accountsToForwardView.push(video.VideoChannel.Account) 53
54 const followersException = [ byAccount ]
55 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
56}
57
58async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
59 const url = getVideoDislikeActivityPubUrl(byAccount, video)
60 const dislikeActivity = createDislikeActivityData(byAccount, video)
61
62 const audience = getOriginVideoAudience(video)
63 const data = await createActivityData(url, byAccount, dislikeActivity, audience)
64
65 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
66}
48 67
49 // Don't forward view to server that sent it to us 68async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
50 const index = accountsToForwardView.findIndex(a => a.id === byAccount.id) 69 const url = getVideoDislikeActivityPubUrl(byAccount, video)
51 if (index) accountsToForwardView.splice(index, 1) 70 const dislikeActivity = createDislikeActivityData(byAccount, video)
71
72 const audience = getVideoFollowersAudience(video)
73 const data = await createActivityData(url, byAccount, dislikeActivity, audience)
74
75 const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
76 const serverAccount = await getServerAccount()
52 77
53 const followersException = [ byAccount ] 78 const followersException = [ byAccount ]
54 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) 79 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
@@ -71,6 +96,16 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje
71 return activity 96 return activity
72} 97}
73 98
99function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) {
100 const obj = {
101 type: 'Dislike',
102 actor: byAccount.url,
103 object: video.url
104 }
105
106 return obj
107}
108
74// --------------------------------------------------------------------------- 109// ---------------------------------------------------------------------------
75 110
76export { 111export {
@@ -78,7 +113,10 @@ export {
78 sendVideoAbuse, 113 sendVideoAbuse,
79 createActivityData, 114 createActivityData,
80 sendCreateViewToOrigin, 115 sendCreateViewToOrigin,
81 sendCreateViewToVideoFollowers 116 sendCreateViewToVideoFollowers,
117 sendCreateDislikeToOrigin,
118 sendCreateDislikeToVideoFollowers,
119 createDislikeActivityData
82} 120}
83 121
84// --------------------------------------------------------------------------- 122// ---------------------------------------------------------------------------