aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-27 10:39:31 +0100
committerChocobozzz <me@florianbigard.com>2017-12-27 10:39:31 +0100
commitea44f375f5d3da06ca0aebfe871b9f924a26ec29 (patch)
treead2e3a458fdbeb11fae8b2215e0619df1aa6e20c /server/lib/activitypub/send
parente2e22e40f91018cfaf244e0df9a4a93e4f6d0502 (diff)
downloadPeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.gz
PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.zst
PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.zip
Send video comment comments to followers/origin
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r--server/lib/activitypub/send/send-create.ts71
1 files changed, 46 insertions, 25 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index 27b03c45f..ca50460be 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -5,14 +5,10 @@ import { getServerActor } from '../../../helpers'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
7import { VideoAbuseModel } from '../../../models/video/video-abuse' 7import { VideoAbuseModel } from '../../../models/video/video-abuse'
8import { VideoCommentModel } from '../../../models/video/video-comment'
8import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' 9import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
9import { 10import {
10 audiencify, 11 audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience,
11 broadcastToFollowers,
12 getActorsInvolvedInVideo,
13 getAudience,
14 getObjectFollowersAudience,
15 getOriginVideoAudience,
16 unicastTo 12 unicastTo
17} from './misc' 13} from './misc'
18 14
@@ -37,24 +33,49 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
37 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) 33 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
38} 34}
39 35
36async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) {
37 const byActor = comment.Account.Actor
38
39 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t)
40 const audience = getOriginVideoAudience(comment.Video, actorsInvolvedInVideo)
41
42 const commentObject = comment.toActivityPubObject()
43 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
44
45 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t)
46}
47
48async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) {
49 const byActor = comment.Account.Actor
50
51 const actorsToForwardView = await getActorsInvolvedInVideo(comment.Video, t)
52 const audience = getObjectFollowersAudience(actorsToForwardView)
53
54 const commentObject = comment.toActivityPubObject()
55 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
56
57 const followersException = [ byActor ]
58 return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException)
59}
60
40async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 61async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
41 const url = getVideoViewActivityPubUrl(byActor, video) 62 const url = getVideoViewActivityPubUrl(byActor, video)
42 const viewActivity = createViewActivityData(byActor, video) 63 const viewActivityData = createViewActivityData(byActor, video)
43 64
44 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 65 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
45 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 66 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
46 const data = await createActivityData(url, byActor, viewActivity, t, audience) 67 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
47 68
48 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) 69 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
49} 70}
50 71
51async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 72async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
52 const url = getVideoViewActivityPubUrl(byActor, video) 73 const url = getVideoViewActivityPubUrl(byActor, video)
53 const viewActivity = createViewActivityData(byActor, video) 74 const viewActivityData = createViewActivityData(byActor, video)
54 75
55 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 76 const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
56 const audience = getObjectFollowersAudience(actorsToForwardView) 77 const audience = getObjectFollowersAudience(actorsToForwardView)
57 const data = await createActivityData(url, byActor, viewActivity, t, audience) 78 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
58 79
59 // Use the server actor to send the view 80 // Use the server actor to send the view
60 const serverActor = await getServerActor() 81 const serverActor = await getServerActor()
@@ -64,22 +85,22 @@ async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: Video
64 85
65async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 86async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
66 const url = getVideoDislikeActivityPubUrl(byActor, video) 87 const url = getVideoDislikeActivityPubUrl(byActor, video)
67 const dislikeActivity = createDislikeActivityData(byActor, video) 88 const dislikeActivityData = createDislikeActivityData(byActor, video)
68 89
69 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 90 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
70 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 91 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
71 const data = await createActivityData(url, byActor, dislikeActivity, t, audience) 92 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
72 93
73 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) 94 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
74} 95}
75 96
76async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 97async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
77 const url = getVideoDislikeActivityPubUrl(byActor, video) 98 const url = getVideoDislikeActivityPubUrl(byActor, video)
78 const dislikeActivity = createDislikeActivityData(byActor, video) 99 const dislikeActivityData = createDislikeActivityData(byActor, video)
79 100
80 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 101 const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
81 const audience = getObjectFollowersAudience(actorsToForwardView) 102 const audience = getObjectFollowersAudience(actorsToForwardView)
82 const data = await createActivityData(url, byActor, dislikeActivity, t, audience) 103 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
83 104
84 const followersException = [ byActor ] 105 const followersException = [ byActor ]
85 return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) 106 return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException)
@@ -112,6 +133,14 @@ function createDislikeActivityData (byActor: ActorModel, video: VideoModel) {
112 } 133 }
113} 134}
114 135
136function createViewActivityData (byActor: ActorModel, video: VideoModel) {
137 return {
138 type: 'View',
139 actor: byActor.url,
140 object: video.url
141 }
142}
143
115// --------------------------------------------------------------------------- 144// ---------------------------------------------------------------------------
116 145
117export { 146export {
@@ -122,15 +151,7 @@ export {
122 sendCreateViewToVideoFollowers, 151 sendCreateViewToVideoFollowers,
123 sendCreateDislikeToOrigin, 152 sendCreateDislikeToOrigin,
124 sendCreateDislikeToVideoFollowers, 153 sendCreateDislikeToVideoFollowers,
125 createDislikeActivityData 154 createDislikeActivityData,
126} 155 sendCreateVideoCommentToOrigin,
127 156 sendCreateVideoCommentToVideoFollowers
128// ---------------------------------------------------------------------------
129
130function createViewActivityData (byActor: ActorModel, video: VideoModel) {
131 return {
132 type: 'View',
133 actor: byActor.url,
134 object: video.url
135 }
136} 157}