diff options
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 226 |
1 files changed, 0 insertions, 226 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts deleted file mode 100644 index 2cd4db14d..000000000 --- a/server/lib/activitypub/send/send-create.ts +++ /dev/null | |||
@@ -1,226 +0,0 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { getServerActor } from '@server/models/application/application' | ||
3 | import { | ||
4 | ActivityAudience, | ||
5 | ActivityCreate, | ||
6 | ActivityCreateObject, | ||
7 | ContextType, | ||
8 | VideoCommentObject, | ||
9 | VideoPlaylistPrivacy, | ||
10 | VideoPrivacy | ||
11 | } from '@shared/models' | ||
12 | import { logger, loggerTagsFactory } from '../../../helpers/logger' | ||
13 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
14 | import { | ||
15 | MActorLight, | ||
16 | MCommentOwnerVideo, | ||
17 | MLocalVideoViewerWithWatchSections, | ||
18 | MVideoAccountLight, | ||
19 | MVideoAP, | ||
20 | MVideoPlaylistFull, | ||
21 | MVideoRedundancyFileVideo, | ||
22 | MVideoRedundancyStreamingPlaylistVideo | ||
23 | } from '../../../types/models' | ||
24 | import { audiencify, getAudience } from '../audience' | ||
25 | import { | ||
26 | broadcastToActors, | ||
27 | broadcastToFollowers, | ||
28 | getActorsInvolvedInVideo, | ||
29 | getAudienceFromFollowersOf, | ||
30 | getVideoCommentAudience, | ||
31 | sendVideoActivityToOrigin, | ||
32 | sendVideoRelatedActivity, | ||
33 | unicastTo | ||
34 | } from './shared' | ||
35 | |||
36 | const lTags = loggerTagsFactory('ap', 'create') | ||
37 | |||
38 | async function sendCreateVideo (video: MVideoAP, transaction: Transaction) { | ||
39 | if (!video.hasPrivacyForFederation()) return undefined | ||
40 | |||
41 | logger.info('Creating job to send video creation of %s.', video.url, lTags(video.uuid)) | ||
42 | |||
43 | const byActor = video.VideoChannel.Account.Actor | ||
44 | const videoObject = await video.toActivityPubObject() | ||
45 | |||
46 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) | ||
47 | const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience) | ||
48 | |||
49 | return broadcastToFollowers({ | ||
50 | data: createActivity, | ||
51 | byActor, | ||
52 | toFollowersOf: [ byActor ], | ||
53 | transaction, | ||
54 | contextType: 'Video' | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | async function sendCreateCacheFile ( | ||
59 | byActor: MActorLight, | ||
60 | video: MVideoAccountLight, | ||
61 | fileRedundancy: MVideoRedundancyStreamingPlaylistVideo | MVideoRedundancyFileVideo | ||
62 | ) { | ||
63 | logger.info('Creating job to send file cache of %s.', fileRedundancy.url, lTags(video.uuid)) | ||
64 | |||
65 | return sendVideoRelatedCreateActivity({ | ||
66 | byActor, | ||
67 | video, | ||
68 | url: fileRedundancy.url, | ||
69 | object: fileRedundancy.toActivityPubObject(), | ||
70 | contextType: 'CacheFile' | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | async function sendCreateWatchAction (stats: MLocalVideoViewerWithWatchSections, transaction: Transaction) { | ||
75 | logger.info('Creating job to send create watch action %s.', stats.url, lTags(stats.uuid)) | ||
76 | |||
77 | const byActor = await getServerActor() | ||
78 | |||
79 | const activityBuilder = (audience: ActivityAudience) => { | ||
80 | return buildCreateActivity(stats.url, byActor, stats.toActivityPubObject(), audience) | ||
81 | } | ||
82 | |||
83 | return sendVideoActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' }) | ||
84 | } | ||
85 | |||
86 | async function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, transaction: Transaction) { | ||
87 | if (playlist.privacy === VideoPlaylistPrivacy.PRIVATE) return undefined | ||
88 | |||
89 | logger.info('Creating job to send create video playlist of %s.', playlist.url, lTags(playlist.uuid)) | ||
90 | |||
91 | const byActor = playlist.OwnerAccount.Actor | ||
92 | const audience = getAudience(byActor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) | ||
93 | |||
94 | const object = await playlist.toActivityPubObject(null, transaction) | ||
95 | const createActivity = buildCreateActivity(playlist.url, byActor, object, audience) | ||
96 | |||
97 | const serverActor = await getServerActor() | ||
98 | const toFollowersOf = [ byActor, serverActor ] | ||
99 | |||
100 | if (playlist.VideoChannel) toFollowersOf.push(playlist.VideoChannel.Actor) | ||
101 | |||
102 | return broadcastToFollowers({ | ||
103 | data: createActivity, | ||
104 | byActor, | ||
105 | toFollowersOf, | ||
106 | transaction, | ||
107 | contextType: 'Playlist' | ||
108 | }) | ||
109 | } | ||
110 | |||
111 | async function sendCreateVideoComment (comment: MCommentOwnerVideo, transaction: Transaction) { | ||
112 | logger.info('Creating job to send comment %s.', comment.url) | ||
113 | |||
114 | const isOrigin = comment.Video.isOwned() | ||
115 | |||
116 | const byActor = comment.Account.Actor | ||
117 | const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, transaction) | ||
118 | const commentObject = comment.toActivityPubObject(threadParentComments) as VideoCommentObject | ||
119 | |||
120 | const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction) | ||
121 | // Add the actor that commented too | ||
122 | actorsInvolvedInComment.push(byActor) | ||
123 | |||
124 | const parentsCommentActors = threadParentComments.filter(c => !c.isDeleted()) | ||
125 | .map(c => c.Account.Actor) | ||
126 | |||
127 | let audience: ActivityAudience | ||
128 | if (isOrigin) { | ||
129 | audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin) | ||
130 | } else { | ||
131 | audience = getAudienceFromFollowersOf(actorsInvolvedInComment.concat(parentsCommentActors)) | ||
132 | } | ||
133 | |||
134 | const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience) | ||
135 | |||
136 | // This was a reply, send it to the parent actors | ||
137 | const actorsException = [ byActor ] | ||
138 | await broadcastToActors({ | ||
139 | data: createActivity, | ||
140 | byActor, | ||
141 | toActors: parentsCommentActors, | ||
142 | transaction, | ||
143 | actorsException, | ||
144 | contextType: 'Comment' | ||
145 | }) | ||
146 | |||
147 | // Broadcast to our followers | ||
148 | await broadcastToFollowers({ | ||
149 | data: createActivity, | ||
150 | byActor, | ||
151 | toFollowersOf: [ byActor ], | ||
152 | transaction, | ||
153 | contextType: 'Comment' | ||
154 | }) | ||
155 | |||
156 | // Send to actors involved in the comment | ||
157 | if (isOrigin) { | ||
158 | return broadcastToFollowers({ | ||
159 | data: createActivity, | ||
160 | byActor, | ||
161 | toFollowersOf: actorsInvolvedInComment, | ||
162 | transaction, | ||
163 | actorsException, | ||
164 | contextType: 'Comment' | ||
165 | }) | ||
166 | } | ||
167 | |||
168 | // Send to origin | ||
169 | return transaction.afterCommit(() => { | ||
170 | return unicastTo({ | ||
171 | data: createActivity, | ||
172 | byActor, | ||
173 | toActorUrl: comment.Video.VideoChannel.Account.Actor.getSharedInbox(), | ||
174 | contextType: 'Comment' | ||
175 | }) | ||
176 | }) | ||
177 | } | ||
178 | |||
179 | function buildCreateActivity <T extends ActivityCreateObject> ( | ||
180 | url: string, | ||
181 | byActor: MActorLight, | ||
182 | object: T, | ||
183 | audience?: ActivityAudience | ||
184 | ): ActivityCreate<T> { | ||
185 | if (!audience) audience = getAudience(byActor) | ||
186 | |||
187 | return audiencify( | ||
188 | { | ||
189 | type: 'Create' as 'Create', | ||
190 | id: url + '/activity', | ||
191 | actor: byActor.url, | ||
192 | object: typeof object === 'string' | ||
193 | ? object | ||
194 | : audiencify(object, audience) | ||
195 | }, | ||
196 | audience | ||
197 | ) | ||
198 | } | ||
199 | |||
200 | // --------------------------------------------------------------------------- | ||
201 | |||
202 | export { | ||
203 | sendCreateVideo, | ||
204 | buildCreateActivity, | ||
205 | sendCreateVideoComment, | ||
206 | sendCreateVideoPlaylist, | ||
207 | sendCreateCacheFile, | ||
208 | sendCreateWatchAction | ||
209 | } | ||
210 | |||
211 | // --------------------------------------------------------------------------- | ||
212 | |||
213 | async function sendVideoRelatedCreateActivity (options: { | ||
214 | byActor: MActorLight | ||
215 | video: MVideoAccountLight | ||
216 | url: string | ||
217 | object: any | ||
218 | contextType: ContextType | ||
219 | transaction?: Transaction | ||
220 | }) { | ||
221 | const activityBuilder = (audience: ActivityAudience) => { | ||
222 | return buildCreateActivity(options.url, options.byActor, options.object, audience) | ||
223 | } | ||
224 | |||
225 | return sendVideoRelatedActivity(activityBuilder, options) | ||
226 | } | ||