diff options
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 9fbaa8196..d26c24838 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -1,111 +1,112 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
3 | import { getServerAccount } from '../../../helpers' | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { AccountModel } from '../../../models/account/account' | 4 | import { getServerActor } from '../../../helpers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | ||
5 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
7 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
9 | import { | 9 | import { |
10 | broadcastToFollowers, | 10 | broadcastToFollowers, |
11 | getAccountsInvolvedInVideo, | 11 | getActorsInvolvedInVideo, |
12 | getAudience, | 12 | getAudience, |
13 | getObjectFollowersAudience, | 13 | getObjectFollowersAudience, |
14 | getOriginVideoAudience, | 14 | getOriginVideoAudience, |
15 | unicastTo | 15 | unicastTo |
16 | } from './misc' | 16 | } from './misc' |
17 | 17 | ||
18 | async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { | 18 | async function sendCreateVideo (video: VideoModel, t: Transaction) { |
19 | const byAccount = videoChannel.Account | 19 | const byActor = video.VideoChannel.Account.Actor |
20 | 20 | ||
21 | const videoChannelObject = videoChannel.toActivityPubObject() | 21 | const videoObject = video.toActivityPubObject() |
22 | const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t) | 22 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) |
23 | const data = await createActivityData(video.url, byActor, videoObject, t, audience) | ||
23 | 24 | ||
24 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 25 | return broadcastToFollowers(data, byActor, [ byActor ], t) |
25 | } | 26 | } |
26 | 27 | ||
27 | async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { | 28 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
28 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 29 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
29 | 30 | ||
30 | const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } | 31 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } |
31 | const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience) | 32 | const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience) |
32 | 33 | ||
33 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 34 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
34 | } | 35 | } |
35 | 36 | ||
36 | async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { | 37 | async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
37 | const url = getVideoViewActivityPubUrl(byAccount, video) | 38 | const url = getVideoViewActivityPubUrl(byActor, video) |
38 | const viewActivity = createViewActivityData(byAccount, video) | 39 | const viewActivity = createViewActivityData(byActor, video) |
39 | 40 | ||
40 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | 41 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
41 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | 42 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) |
42 | const data = await createActivityData(url, byAccount, viewActivity, t, audience) | 43 | const data = await createActivityData(url, byActor, viewActivity, t, audience) |
43 | 44 | ||
44 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 45 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
45 | } | 46 | } |
46 | 47 | ||
47 | async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { | 48 | async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
48 | const url = getVideoViewActivityPubUrl(byAccount, video) | 49 | const url = getVideoViewActivityPubUrl(byActor, video) |
49 | const viewActivity = createViewActivityData(byAccount, video) | 50 | const viewActivity = createViewActivityData(byActor, video) |
50 | 51 | ||
51 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) | 52 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
52 | const audience = getObjectFollowersAudience(accountsToForwardView) | 53 | const audience = getObjectFollowersAudience(actorsToForwardView) |
53 | const data = await createActivityData(url, byAccount, viewActivity, t, audience) | 54 | const data = await createActivityData(url, byActor, viewActivity, t, audience) |
54 | 55 | ||
55 | // Use the server account to send the view, because it could be an unregistered account | 56 | // Use the server actor to send the view |
56 | const serverAccount = await getServerAccount() | 57 | const serverActor = await getServerActor() |
57 | const followersException = [ byAccount ] | 58 | const followersException = [ byActor ] |
58 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 59 | return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) |
59 | } | 60 | } |
60 | 61 | ||
61 | async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { | 62 | async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
62 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 63 | const url = getVideoDislikeActivityPubUrl(byActor, video) |
63 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 64 | const dislikeActivity = createDislikeActivityData(byActor, video) |
64 | 65 | ||
65 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | 66 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
66 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | 67 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) |
67 | const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) | 68 | const data = await createActivityData(url, byActor, dislikeActivity, t, audience) |
68 | 69 | ||
69 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 70 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
70 | } | 71 | } |
71 | 72 | ||
72 | async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { | 73 | async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
73 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 74 | const url = getVideoDislikeActivityPubUrl(byActor, video) |
74 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 75 | const dislikeActivity = createDislikeActivityData(byActor, video) |
75 | 76 | ||
76 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) | 77 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
77 | const audience = getObjectFollowersAudience(accountsToForwardView) | 78 | const audience = getObjectFollowersAudience(actorsToForwardView) |
78 | const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) | 79 | const data = await createActivityData(url, byActor, dislikeActivity, t, audience) |
79 | 80 | ||
80 | const followersException = [ byAccount ] | 81 | const followersException = [ byActor ] |
81 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) | 82 | return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) |
82 | } | 83 | } |
83 | 84 | ||
84 | async function createActivityData ( | 85 | async function createActivityData ( |
85 | url: string, | 86 | url: string, |
86 | byAccount: AccountModel, | 87 | byActor: ActorModel, |
87 | object: any, | 88 | object: any, |
88 | t: Transaction, | 89 | t: Transaction, |
89 | audience?: ActivityAudience | 90 | audience?: ActivityAudience |
90 | ): Promise<ActivityCreate> { | 91 | ): Promise<ActivityCreate> { |
91 | if (!audience) { | 92 | if (!audience) { |
92 | audience = await getAudience(byAccount, t) | 93 | audience = await getAudience(byActor, t) |
93 | } | 94 | } |
94 | 95 | ||
95 | return { | 96 | return { |
96 | type: 'Create', | 97 | type: 'Create', |
97 | id: url, | 98 | id: url, |
98 | actor: byAccount.url, | 99 | actor: byActor.url, |
99 | to: audience.to, | 100 | to: audience.to, |
100 | cc: audience.cc, | 101 | cc: audience.cc, |
101 | object | 102 | object |
102 | } | 103 | } |
103 | } | 104 | } |
104 | 105 | ||
105 | function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) { | 106 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { |
106 | return { | 107 | return { |
107 | type: 'Dislike', | 108 | type: 'Dislike', |
108 | actor: byAccount.url, | 109 | actor: byActor.url, |
109 | object: video.url | 110 | object: video.url |
110 | } | 111 | } |
111 | } | 112 | } |
@@ -113,7 +114,7 @@ function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) | |||
113 | // --------------------------------------------------------------------------- | 114 | // --------------------------------------------------------------------------- |
114 | 115 | ||
115 | export { | 116 | export { |
116 | sendCreateVideoChannel, | 117 | sendCreateVideo, |
117 | sendVideoAbuse, | 118 | sendVideoAbuse, |
118 | createActivityData, | 119 | createActivityData, |
119 | sendCreateViewToOrigin, | 120 | sendCreateViewToOrigin, |
@@ -125,10 +126,10 @@ export { | |||
125 | 126 | ||
126 | // --------------------------------------------------------------------------- | 127 | // --------------------------------------------------------------------------- |
127 | 128 | ||
128 | function createViewActivityData (byAccount: AccountModel, video: VideoModel) { | 129 | function createViewActivityData (byActor: ActorModel, video: VideoModel) { |
129 | return { | 130 | return { |
130 | type: 'View', | 131 | type: 'View', |
131 | actor: byAccount.url, | 132 | actor: byActor.url, |
132 | object: video.url | 133 | object: video.url |
133 | } | 134 | } |
134 | } | 135 | } |