diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-05 11:19:25 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-05 11:19:25 +0100 |
commit | d7e70384a360cda51fe23712331110a5c8b1124c (patch) | |
tree | 385609669c92936a5c66ae028c331fb4a9b5943e /server/lib/activitypub | |
parent | 2890b615f31ab7d519d8be66b49ff8712df90c51 (diff) | |
download | PeerTube-d7e70384a360cda51fe23712331110a5c8b1124c.tar.gz PeerTube-d7e70384a360cda51fe23712331110a5c8b1124c.tar.zst PeerTube-d7e70384a360cda51fe23712331110a5c8b1124c.zip |
Add mentions to comments
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/send/misc.ts | 38 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 18 |
2 files changed, 44 insertions, 12 deletions
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) { |