aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/audience.ts92
-rw-r--r--server/lib/activitypub/index.ts1
-rw-r--r--server/lib/activitypub/process/process-announce.ts2
-rw-r--r--server/lib/activitypub/process/process-create.ts3
-rw-r--r--server/lib/activitypub/process/process-delete.ts2
-rw-r--r--server/lib/activitypub/process/process-like.ts2
-rw-r--r--server/lib/activitypub/process/process-undo.ts2
-rw-r--r--server/lib/activitypub/process/process-update.ts3
-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
17 files changed, 130 insertions, 133 deletions
diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts
new file mode 100644
index 000000000..916358fe2
--- /dev/null
+++ b/server/lib/activitypub/audience.ts
@@ -0,0 +1,92 @@
1import { Transaction } from 'sequelize'
2import { ActivityAudience } from '../../../shared/models/activitypub'
3import { ACTIVITY_PUB } from '../../initializers'
4import { ActorModel } from '../../models/activitypub/actor'
5import { VideoModel } from '../../models/video/video'
6import { VideoCommentModel } from '../../models/video/video-comment'
7import { VideoShareModel } from '../../models/video/video-share'
8
9function getVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) {
10 return {
11 to: [ video.VideoChannel.Account.Actor.url ],
12 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
13 }
14}
15
16function getVideoCommentAudience (
17 videoComment: VideoCommentModel,
18 threadParentComments: VideoCommentModel[],
19 actorsInvolvedInVideo: ActorModel[],
20 isOrigin = false
21) {
22 const to = [ ACTIVITY_PUB.PUBLIC ]
23 const cc = [ ]
24
25 // Owner of the video we comment
26 if (isOrigin === false) {
27 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
28 }
29
30 // Followers of the poster
31 cc.push(videoComment.Account.Actor.followersUrl)
32
33 // Send to actors we reply to
34 for (const parentComment of threadParentComments) {
35 cc.push(parentComment.Account.Actor.url)
36 }
37
38 return {
39 to,
40 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
41 }
42}
43
44function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) {
45 return {
46 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
47 cc: []
48 }
49}
50
51async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
52 const actors = await VideoShareModel.loadActorsByShare(video.id, t)
53 actors.push(video.VideoChannel.Account.Actor)
54
55 return actors
56}
57
58async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) {
59 return buildAudience([ actorSender.followersUrl ], isPublic)
60}
61
62function buildAudience (followerInboxUrls: string[], isPublic = true) {
63 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
64 let to = []
65 let cc = []
66
67 if (isPublic) {
68 to = [ ACTIVITY_PUB.PUBLIC ]
69 cc = followerInboxUrls
70 } else { // Unlisted
71 to = [ ]
72 cc = [ ]
73 }
74
75 return { to, cc }
76}
77
78function audiencify <T> (object: T, audience: ActivityAudience) {
79 return Object.assign(object, audience)
80}
81
82// ---------------------------------------------------------------------------
83
84export {
85 buildAudience,
86 getAudience,
87 getVideoAudience,
88 getActorsInvolvedInVideo,
89 getObjectFollowersAudience,
90 audiencify,
91 getVideoCommentAudience
92}
diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts
index 88064c6b6..6906bf9d3 100644
--- a/server/lib/activitypub/index.ts
+++ b/server/lib/activitypub/index.ts
@@ -1,7 +1,6 @@
1export * from './process' 1export * from './process'
2export * from './send' 2export * from './send'
3export * from './actor' 3export * from './actor'
4export * from './fetch'
5export * from './share' 4export * from './share'
6export * from './videos' 5export * from './videos'
7export * from './video-comments' 6export * from './video-comments'
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 09f2e80f3..a6e1e2d47 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -5,7 +5,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoModel } from '../../../models/video/video' 5import { VideoModel } from '../../../models/video/video'
6import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
7import { getOrCreateActorAndServerAndModel } from '../actor' 7import { getOrCreateActorAndServerAndModel } from '../actor'
8import { forwardActivity } from '../send/misc' 8import { forwardActivity } from '../send/utils'
9import { getOrCreateAccountAndVideoAndChannel } from '../videos' 9import { getOrCreateAccountAndVideoAndChannel } from '../videos'
10 10
11async function processAnnounceActivity (activity: ActivityAnnounce) { 11async function processAnnounceActivity (activity: ActivityAnnounce) {
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index ee180b765..99a5f6f9c 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -9,9 +9,10 @@ import { ActorModel } from '../../../models/activitypub/actor'
9import { VideoAbuseModel } from '../../../models/video/video-abuse' 9import { VideoAbuseModel } from '../../../models/video/video-abuse'
10import { VideoCommentModel } from '../../../models/video/video-comment' 10import { VideoCommentModel } from '../../../models/video/video-comment'
11import { getOrCreateActorAndServerAndModel } from '../actor' 11import { getOrCreateActorAndServerAndModel } from '../actor'
12import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc' 12import { getActorsInvolvedInVideo } from '../audience'
13import { resolveThread } from '../video-comments' 13import { resolveThread } from '../video-comments'
14import { getOrCreateAccountAndVideoAndChannel } from '../videos' 14import { getOrCreateAccountAndVideoAndChannel } from '../videos'
15import { forwardActivity } from '../send/utils'
15 16
16async function processCreateActivity (activity: ActivityCreate) { 17async function processCreateActivity (activity: ActivityCreate) {
17 const activityObject = activity.object 18 const activityObject = activity.object
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index b58f6c04a..8310b70f0 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -8,7 +8,7 @@ import { VideoModel } from '../../../models/video/video'
8import { VideoChannelModel } from '../../../models/video/video-channel' 8import { VideoChannelModel } from '../../../models/video/video-channel'
9import { VideoCommentModel } from '../../../models/video/video-comment' 9import { VideoCommentModel } from '../../../models/video/video-comment'
10import { getOrCreateActorAndServerAndModel } from '../actor' 10import { getOrCreateActorAndServerAndModel } from '../actor'
11import { forwardActivity } from '../send/misc' 11import { forwardActivity } from '../send/utils'
12 12
13async function processDeleteActivity (activity: ActivityDelete) { 13async function processDeleteActivity (activity: ActivityDelete) {
14 const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id 14 const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index 0d161b126..d219e76eb 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -4,7 +4,7 @@ import { sequelizeTypescript } from '../../../initializers'
4import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 4import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { getOrCreateActorAndServerAndModel } from '../actor' 6import { getOrCreateActorAndServerAndModel } from '../actor'
7import { forwardActivity } from '../send/misc' 7import { forwardActivity } from '../send/utils'
8import { getOrCreateAccountAndVideoAndChannel } from '../videos' 8import { getOrCreateAccountAndVideoAndChannel } from '../videos'
9 9
10async function processLikeActivity (activity: ActivityLike) { 10async function processLikeActivity (activity: ActivityLike) {
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index 9b024d15f..d023f7029 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -8,7 +8,7 @@ import { AccountModel } from '../../../models/account/account'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 8import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { ActorModel } from '../../../models/activitypub/actor' 9import { ActorModel } from '../../../models/activitypub/actor'
10import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 10import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
11import { forwardActivity } from '../send/misc' 11import { forwardActivity } from '../send/utils'
12import { getOrCreateAccountAndVideoAndChannel } from '../videos' 12import { getOrCreateAccountAndVideoAndChannel } from '../videos'
13import { VideoShareModel } from '../../../models/video/video-share' 13import { VideoShareModel } from '../../../models/video/video-share'
14 14
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 0dd657c2b..2750f48c3 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -14,7 +14,8 @@ import { VideoFileModel } from '../../../models/video/video-file'
14import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' 14import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
15import { 15import {
16 generateThumbnailFromUrl, 16 generateThumbnailFromUrl,
17 getOrCreateAccountAndVideoAndChannel, getOrCreateVideoChannel, 17 getOrCreateAccountAndVideoAndChannel,
18 getOrCreateVideoChannel,
18 videoActivityObjectToDBAttributes, 19 videoActivityObjectToDBAttributes,
19 videoFileActivityUrlToDBAttributes 20 videoFileActivityUrlToDBAttributes
20} from '../videos' 21} from '../videos'
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}