diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/activitypub/client.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/misc.ts | 38 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 18 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 41 |
4 files changed, 85 insertions, 15 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index e0ab3188b..717473912 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -114,5 +114,6 @@ async function videoChannelController (req: express.Request, res: express.Respon | |||
114 | async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { |
115 | const videoComment: VideoCommentModel = res.locals.videoComment | 115 | const videoComment: VideoCommentModel = res.locals.videoComment |
116 | 116 | ||
117 | return res.json(videoComment.toActivityPubObject()) | 117 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) |
118 | return res.json(videoComment.toActivityPubObject(threadParentComments)) | ||
118 | } | 119 | } |
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index 05f327b29..4aa514c15 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts | |||
@@ -5,6 +5,7 @@ import { ACTIVITY_PUB } from '../../../initializers' | |||
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
7 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
8 | import { VideoShareModel } from '../../../models/video/video-share' | 9 | import { VideoShareModel } from '../../../models/video/video-share' |
9 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' | 10 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' |
10 | 11 | ||
@@ -84,6 +85,34 @@ function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: Actor | |||
84 | } | 85 | } |
85 | } | 86 | } |
86 | 87 | ||
88 | function getOriginVideoCommentAudience ( | ||
89 | videoComment: VideoCommentModel, | ||
90 | threadParentComments: VideoCommentModel[], | ||
91 | actorsInvolvedInVideo: ActorModel[], | ||
92 | isOrigin = false | ||
93 | ) { | ||
94 | const to = [ ACTIVITY_PUB.PUBLIC ] | ||
95 | const cc = [ ] | ||
96 | |||
97 | // Owner of the video we comment | ||
98 | if (isOrigin === false) { | ||
99 | cc.push(videoComment.Video.VideoChannel.Account.Actor.url) | ||
100 | } | ||
101 | |||
102 | // Followers of the poster | ||
103 | cc.push(videoComment.Account.Actor.followersUrl) | ||
104 | |||
105 | // Send to actors we reply to | ||
106 | for (const parentComment of threadParentComments) { | ||
107 | cc.push(parentComment.Account.Actor.url) | ||
108 | } | ||
109 | |||
110 | return { | ||
111 | to, | ||
112 | cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl)) | ||
113 | } | ||
114 | } | ||
115 | |||
87 | function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { | 116 | function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { |
88 | return { | 117 | return { |
89 | to: actorsInvolvedInObject.map(a => a.followersUrl), | 118 | to: actorsInvolvedInObject.map(a => a.followersUrl), |
@@ -92,10 +121,10 @@ function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { | |||
92 | } | 121 | } |
93 | 122 | ||
94 | async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { | 123 | async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { |
95 | const actorsToForwardView = await VideoShareModel.loadActorsByShare(video.id, t) | 124 | const actors = await VideoShareModel.loadActorsByShare(video.id, t) |
96 | actorsToForwardView.push(video.VideoChannel.Account.Actor) | 125 | actors.push(video.VideoChannel.Account.Actor) |
97 | 126 | ||
98 | return actorsToForwardView | 127 | return actors |
99 | } | 128 | } |
100 | 129 | ||
101 | async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { | 130 | async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { |
@@ -138,5 +167,6 @@ export { | |||
138 | getActorsInvolvedInVideo, | 167 | getActorsInvolvedInVideo, |
139 | getObjectFollowersAudience, | 168 | getObjectFollowersAudience, |
140 | forwardActivity, | 169 | forwardActivity, |
141 | audiencify | 170 | audiencify, |
171 | getOriginVideoCommentAudience | ||
142 | } | 172 | } |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 2f5cdc8c5..e2ee639d9 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -8,7 +8,8 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' | |||
8 | import { VideoCommentModel } from '../../../models/video/video-comment' | 8 | import { VideoCommentModel } from '../../../models/video/video-comment' |
9 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 9 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
10 | import { | 10 | import { |
11 | audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience, | 11 | audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, |
12 | getOriginVideoAudience, getOriginVideoCommentAudience, | ||
12 | unicastTo | 13 | unicastTo |
13 | } from './misc' | 14 | } from './misc' |
14 | 15 | ||
@@ -35,11 +36,12 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, | |||
35 | 36 | ||
36 | async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { | 37 | async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { |
37 | const byActor = comment.Account.Actor | 38 | const byActor = comment.Account.Actor |
39 | const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) | ||
40 | const commentObject = comment.toActivityPubObject(threadParentComments) | ||
38 | 41 | ||
39 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) | 42 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) |
40 | const audience = getOriginVideoAudience(comment.Video, actorsInvolvedInVideo) | 43 | const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) |
41 | 44 | ||
42 | const commentObject = comment.toActivityPubObject() | ||
43 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) | 45 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) |
44 | 46 | ||
45 | return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t) | 47 | return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
@@ -47,15 +49,15 @@ async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Tr | |||
47 | 49 | ||
48 | async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { | 50 | async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { |
49 | const byActor = comment.Account.Actor | 51 | const byActor = comment.Account.Actor |
52 | const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) | ||
53 | const commentObject = comment.toActivityPubObject(threadParentComments) | ||
50 | 54 | ||
51 | const actorsToForwardView = await getActorsInvolvedInVideo(comment.Video, t) | 55 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) |
52 | const audience = getObjectFollowersAudience(actorsToForwardView) | 56 | const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) |
53 | |||
54 | const commentObject = comment.toActivityPubObject() | ||
55 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) | 57 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) |
56 | 58 | ||
57 | const followersException = [ byActor ] | 59 | const followersException = [ byActor ] |
58 | return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) | 60 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
59 | } | 61 | } |
60 | 62 | ||
61 | async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { | 63 | async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 66fca2484..dbb2fe429 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -3,6 +3,7 @@ import { | |||
3 | AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, | 3 | AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, |
4 | UpdatedAt | 4 | UpdatedAt |
5 | } from 'sequelize-typescript' | 5 | } from 'sequelize-typescript' |
6 | import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' | ||
6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 7 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 8 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 9 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
@@ -270,6 +271,30 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
270 | }) | 271 | }) |
271 | } | 272 | } |
272 | 273 | ||
274 | static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction) { | ||
275 | const query = { | ||
276 | order: [ [ 'createdAt', 'ASC' ] ], | ||
277 | where: { | ||
278 | [ Sequelize.Op.or ]: [ | ||
279 | { id: comment.getThreadId() }, | ||
280 | { originCommentId: comment.getThreadId() } | ||
281 | ], | ||
282 | id: { | ||
283 | [ Sequelize.Op.ne ]: comment.id | ||
284 | } | ||
285 | }, | ||
286 | transaction: t | ||
287 | } | ||
288 | |||
289 | return VideoCommentModel | ||
290 | .scope([ ScopeNames.WITH_ACCOUNT ]) | ||
291 | .findAll(query) | ||
292 | } | ||
293 | |||
294 | getThreadId (): number { | ||
295 | return this.originCommentId || this.id | ||
296 | } | ||
297 | |||
273 | isOwned () { | 298 | isOwned () { |
274 | return this.Account.isOwned() | 299 | return this.Account.isOwned() |
275 | } | 300 | } |
@@ -289,7 +314,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
289 | } as VideoComment | 314 | } as VideoComment |
290 | } | 315 | } |
291 | 316 | ||
292 | toActivityPubObject (): VideoCommentObject { | 317 | toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject { |
293 | let inReplyTo: string | 318 | let inReplyTo: string |
294 | // New thread, so in AS we reply to the video | 319 | // New thread, so in AS we reply to the video |
295 | if (this.inReplyToCommentId === null) { | 320 | if (this.inReplyToCommentId === null) { |
@@ -298,6 +323,17 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
298 | inReplyTo = this.InReplyToVideoComment.url | 323 | inReplyTo = this.InReplyToVideoComment.url |
299 | } | 324 | } |
300 | 325 | ||
326 | const tag: ActivityTagObject[] = [] | ||
327 | for (const parentComment of threadParentComments) { | ||
328 | const actor = parentComment.Account.Actor | ||
329 | |||
330 | tag.push({ | ||
331 | type: 'Mention', | ||
332 | href: actor.url, | ||
333 | name: `@${actor.preferredUsername}@${actor.getHost()}` | ||
334 | }) | ||
335 | } | ||
336 | |||
301 | return { | 337 | return { |
302 | type: 'Note' as 'Note', | 338 | type: 'Note' as 'Note', |
303 | id: this.url, | 339 | id: this.url, |
@@ -306,7 +342,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
306 | updated: this.updatedAt.toISOString(), | 342 | updated: this.updatedAt.toISOString(), |
307 | published: this.createdAt.toISOString(), | 343 | published: this.createdAt.toISOString(), |
308 | url: this.url, | 344 | url: this.url, |
309 | attributedTo: this.Account.Actor.url | 345 | attributedTo: this.Account.Actor.url, |
346 | tag | ||
310 | } | 347 | } |
311 | } | 348 | } |
312 | } | 349 | } |