aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-25 11:32:36 +0200
committerChocobozzz <me@florianbigard.com>2018-05-25 11:33:04 +0200
commite251f170b00b2014ac4e823113c6ff40e3fb1471 (patch)
tree50b83c1d41dd80acd0fa745d6d3780f4204b04fa /server/lib/activitypub/send
parent16f29007dc6ad9c539195d7a7c1cde45d626ce91 (diff)
downloadPeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.tar.gz
PeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.tar.zst
PeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.zip
Split files in activitypub server
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r--server/lib/activitypub/send/send-accept.ts2
-rw-r--r--server/lib/activitypub/send/send-announce.ts3
-rw-r--r--server/lib/activitypub/send/send-create.ts14
-rw-r--r--server/lib/activitypub/send/send-delete.ts3
-rw-r--r--server/lib/activitypub/send/send-follow.ts2
-rw-r--r--server/lib/activitypub/send/send-like.ts13
-rw-r--r--server/lib/activitypub/send/send-undo.ts15
-rw-r--r--server/lib/activitypub/send/send-update.ts3
-rw-r--r--server/lib/activitypub/send/utils.ts (renamed from server/lib/activitypub/send/misc.ts)101
9 files changed, 30 insertions, 126 deletions
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index 064fd88d2..44644a22f 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -2,7 +2,7 @@ import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activi
2import { ActorModel } from '../../../models/activitypub/actor' 2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' 4import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
5import { unicastTo } from './misc' 5import { unicastTo } from './utils'
6import { followActivityData } from './send-follow' 6import { followActivityData } from './send-follow'
7 7
8async function sendAccept (actorFollow: ActorFollowModel) { 8async function sendAccept (actorFollow: ActorFollowModel) {
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts
index 4179c9d43..fa1d47259 100644
--- a/server/lib/activitypub/send/send-announce.ts
+++ b/server/lib/activitypub/send/send-announce.ts
@@ -3,7 +3,8 @@ import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/ac
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
6import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc' 6import { broadcastToFollowers } from './utils'
7import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
7 8
8async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { 9async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
9 const announcedObject = video.url 10 const announcedObject = video.url
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index 4ff20b033..3ef4fcd3b 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -7,17 +7,15 @@ import { 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 { VideoCommentModel } from '../../../models/video/video-comment'
9import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' 9import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
10import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils'
10import { 11import {
11 audiencify, 12 audiencify,
12 broadcastToActors,
13 broadcastToFollowers,
14 getActorsInvolvedInVideo, 13 getActorsInvolvedInVideo,
15 getAudience, 14 getAudience,
16 getObjectFollowersAudience, 15 getObjectFollowersAudience,
17 getOriginVideoAudience, 16 getVideoAudience,
18 getVideoCommentAudience, 17 getVideoCommentAudience
19 unicastTo 18} from '../audience'
20} from './misc'
21 19
22async function sendCreateVideo (video: VideoModel, t: Transaction) { 20async function sendCreateVideo (video: VideoModel, t: Transaction) {
23 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 21 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
@@ -83,7 +81,7 @@ async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transa
83 81
84 // Send to origin 82 // Send to origin
85 if (video.isOwned() === false) { 83 if (video.isOwned() === false) {
86 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 84 const audience = getVideoAudience(video, actorsInvolvedInVideo)
87 const data = await createActivityData(url, byActor, viewActivityData, t, audience) 85 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
88 86
89 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 87 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
@@ -107,7 +105,7 @@ async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Tra
107 105
108 // Send to origin 106 // Send to origin
109 if (video.isOwned() === false) { 107 if (video.isOwned() === false) {
110 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 108 const audience = getVideoAudience(video, actorsInvolvedInVideo)
111 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) 109 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
112 110
113 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 111 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index bb5d6913c..e9a8951b5 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -5,7 +5,8 @@ import { VideoModel } from '../../../models/video/video'
5import { VideoCommentModel } from '../../../models/video/video-comment' 5import { VideoCommentModel } from '../../../models/video/video-comment'
6import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
7import { getDeleteActivityPubUrl } from '../url' 7import { getDeleteActivityPubUrl } from '../url'
8import { audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getVideoCommentAudience, unicastTo } from './misc' 8import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils'
9import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
9 10
10async function sendDeleteVideo (video: VideoModel, t: Transaction) { 11async function sendDeleteVideo (video: VideoModel, t: Transaction) {
11 const url = getDeleteActivityPubUrl(video.url) 12 const url = getDeleteActivityPubUrl(video.url)
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 4e9865af4..f81d9a194 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -2,7 +2,7 @@ import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor' 2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { getActorFollowActivityPubUrl } from '../url' 4import { getActorFollowActivityPubUrl } from '../url'
5import { unicastTo } from './misc' 5import { unicastTo } from './utils'
6 6
7function sendFollow (actorFollow: ActorFollowModel) { 7function sendFollow (actorFollow: ActorFollowModel) {
8 const me = actorFollow.ActorFollower 8 const me = actorFollow.ActorFollower
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index fb2b4aaf8..ddeb1fcd2 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -3,15 +3,8 @@ import { ActivityAudience, ActivityLike } from '../../../../shared/models/activi
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { getVideoLikeActivityPubUrl } from '../url' 5import { getVideoLikeActivityPubUrl } from '../url'
6import { 6import { broadcastToFollowers, unicastTo } from './utils'
7 audiencify, 7import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
8 broadcastToFollowers,
9 getActorsInvolvedInVideo,
10 getAudience,
11 getObjectFollowersAudience,
12 getOriginVideoAudience,
13 unicastTo
14} from './misc'
15 8
16async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) { 9async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
17 const url = getVideoLikeActivityPubUrl(byActor, video) 10 const url = getVideoLikeActivityPubUrl(byActor, video)
@@ -20,7 +13,7 @@ async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction)
20 13
21 // Send to origin 14 // Send to origin
22 if (video.isOwned() === false) { 15 if (video.isOwned() === false) {
23 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 16 const audience = getVideoAudience(video, accountsInvolvedInVideo)
24 const data = await likeActivityData(url, byActor, video, t, audience) 17 const data = await likeActivityData(url, byActor, video, t, audience)
25 18
26 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 19 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index adee2192f..9733e66dc 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -11,15 +11,8 @@ import { ActorModel } from '../../../models/activitypub/actor'
11import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 11import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
12import { VideoModel } from '../../../models/video/video' 12import { VideoModel } from '../../../models/video/video'
13import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' 13import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
14import { 14import { broadcastToFollowers, unicastTo } from './utils'
15 audiencify, 15import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
16 broadcastToFollowers,
17 getActorsInvolvedInVideo,
18 getAudience,
19 getObjectFollowersAudience,
20 getOriginVideoAudience,
21 unicastTo
22} from './misc'
23import { createActivityData, createDislikeActivityData } from './send-create' 16import { createActivityData, createDislikeActivityData } from './send-create'
24import { followActivityData } from './send-follow' 17import { followActivityData } from './send-follow'
25import { likeActivityData } from './send-like' 18import { likeActivityData } from './send-like'
@@ -48,7 +41,7 @@ async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transact
48 41
49 // Send to origin 42 // Send to origin
50 if (video.isOwned() === false) { 43 if (video.isOwned() === false) {
51 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 44 const audience = getVideoAudience(video, actorsInvolvedInVideo)
52 const data = await undoActivityData(undoUrl, byActor, object, t, audience) 45 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
53 46
54 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 47 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
@@ -70,7 +63,7 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans
70 const object = await createActivityData(dislikeUrl, byActor, dislikeActivity, t) 63 const object = await createActivityData(dislikeUrl, byActor, dislikeActivity, t)
71 64
72 if (video.isOwned() === false) { 65 if (video.isOwned() === false) {
73 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) 66 const audience = getVideoAudience(video, actorsInvolvedInVideo)
74 const data = await undoActivityData(undoUrl, byActor, object, t, audience) 67 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
75 68
76 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 69 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index e15fecff6..d64b88343 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -7,7 +7,8 @@ import { VideoModel } from '../../../models/video/video'
7import { VideoChannelModel } from '../../../models/video/video-channel' 7import { VideoChannelModel } from '../../../models/video/video-channel'
8import { VideoShareModel } from '../../../models/video/video-share' 8import { VideoShareModel } from '../../../models/video/video-share'
9import { getUpdateActivityPubUrl } from '../url' 9import { getUpdateActivityPubUrl } from '../url'
10import { audiencify, broadcastToFollowers, getAudience } from './misc' 10import { broadcastToFollowers } from './utils'
11import { audiencify, getAudience } from '../audience'
11 12
12async function sendUpdateVideo (video: VideoModel, t: Transaction) { 13async function sendUpdateVideo (video: VideoModel, t: Transaction) {
13 const byActor = video.VideoChannel.Account.Actor 14 const byActor = video.VideoChannel.Account.Actor
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/utils.ts
index 646aa9f0a..80d4463ff 100644
--- a/server/lib/activitypub/send/misc.ts
+++ b/server/lib/activitypub/send/utils.ts
@@ -1,12 +1,8 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' 2import { Activity } from '../../../../shared/models/activitypub'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { ACTIVITY_PUB } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor' 4import { ActorModel } from '../../../models/activitypub/actor'
6import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { VideoModel } from '../../../models/video/video'
8import { VideoCommentModel } from '../../../models/video/video-comment'
9import { VideoShareModel } from '../../../models/video/video-share'
10import { JobQueue } from '../../job-queue' 6import { JobQueue } from '../../job-queue'
11 7
12async function forwardActivity ( 8async function forwardActivity (
@@ -89,78 +85,16 @@ async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) {
89 return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) 85 return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload })
90} 86}
91 87
92function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) { 88// ---------------------------------------------------------------------------
93 return {
94 to: [ video.VideoChannel.Account.Actor.url ],
95 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
96 }
97}
98
99function getVideoCommentAudience (
100 videoComment: VideoCommentModel,
101 threadParentComments: VideoCommentModel[],
102 actorsInvolvedInVideo: ActorModel[],
103 isOrigin = false
104) {
105 const to = [ ACTIVITY_PUB.PUBLIC ]
106 const cc = [ ]
107
108 // Owner of the video we comment
109 if (isOrigin === false) {
110 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
111 }
112
113 // Followers of the poster
114 cc.push(videoComment.Account.Actor.followersUrl)
115
116 // Send to actors we reply to
117 for (const parentComment of threadParentComments) {
118 cc.push(parentComment.Account.Actor.url)
119 }
120
121 return {
122 to,
123 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
124 }
125}
126
127function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) {
128 return {
129 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
130 cc: []
131 }
132}
133
134async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
135 const actors = await VideoShareModel.loadActorsByShare(video.id, t)
136 actors.push(video.VideoChannel.Account.Actor)
137
138 return actors
139}
140
141async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) {
142 return buildAudience([ actorSender.followersUrl ], isPublic)
143}
144
145function buildAudience (followerInboxUrls: string[], isPublic = true) {
146 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
147 let to = []
148 let cc = []
149
150 if (isPublic) {
151 to = [ ACTIVITY_PUB.PUBLIC ]
152 cc = followerInboxUrls
153 } else { // Unlisted
154 to = [ ]
155 cc = [ ]
156 }
157 89
158 return { to, cc } 90export {
91 broadcastToFollowers,
92 unicastTo,
93 forwardActivity,
94 broadcastToActors
159} 95}
160 96
161function audiencify <T> (object: T, audience: ActivityAudience) { 97// ---------------------------------------------------------------------------
162 return Object.assign(object, audience)
163}
164 98
165async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) { 99async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) {
166 const toActorFollowerIds = toActorFollower.map(a => a.id) 100 const toActorFollowerIds = toActorFollower.map(a => a.id)
@@ -175,22 +109,5 @@ async function computeUris (toActors: ActorModel[], actorsException: ActorModel[
175 109
176 const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl) 110 const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl)
177 return Array.from(toActorSharedInboxesSet) 111 return Array.from(toActorSharedInboxesSet)
178 .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) 112 .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1)
179}
180
181// ---------------------------------------------------------------------------
182
183export {
184 broadcastToFollowers,
185 unicastTo,
186 buildAudience,
187 getAudience,
188 getOriginVideoAudience,
189 getActorsInvolvedInVideo,
190 getObjectFollowersAudience,
191 forwardActivity,
192 audiencify,
193 getVideoCommentAudience,
194 computeUris,
195 broadcastToActors
196} 113}