diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-25 11:32:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-25 11:33:04 +0200 |
commit | e251f170b00b2014ac4e823113c6ff40e3fb1471 (patch) | |
tree | 50b83c1d41dd80acd0fa745d6d3780f4204b04fa /server/lib/activitypub | |
parent | 16f29007dc6ad9c539195d7a7c1cde45d626ce91 (diff) | |
download | PeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.tar.gz PeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.tar.zst PeerTube-e251f170b00b2014ac4e823113c6ff40e3fb1471.zip |
Split files in activitypub server
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/audience.ts | 92 | ||||
-rw-r--r-- | server/lib/activitypub/index.ts | 1 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-announce.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 14 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-like.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 3 | ||||
-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 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityAudience } from '../../../shared/models/activitypub' | ||
3 | import { ACTIVITY_PUB } from '../../initializers' | ||
4 | import { ActorModel } from '../../models/activitypub/actor' | ||
5 | import { VideoModel } from '../../models/video/video' | ||
6 | import { VideoCommentModel } from '../../models/video/video-comment' | ||
7 | import { VideoShareModel } from '../../models/video/video-share' | ||
8 | |||
9 | function getVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) { | ||
10 | return { | ||
11 | to: [ video.VideoChannel.Account.Actor.url ], | ||
12 | cc: actorsInvolvedInVideo.map(a => a.followersUrl) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | function 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 | |||
44 | function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { | ||
45 | return { | ||
46 | to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), | ||
47 | cc: [] | ||
48 | } | ||
49 | } | ||
50 | |||
51 | async 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 | |||
58 | async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { | ||
59 | return buildAudience([ actorSender.followersUrl ], isPublic) | ||
60 | } | ||
61 | |||
62 | function 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 | |||
78 | function audiencify <T> (object: T, audience: ActivityAudience) { | ||
79 | return Object.assign(object, audience) | ||
80 | } | ||
81 | |||
82 | // --------------------------------------------------------------------------- | ||
83 | |||
84 | export { | ||
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 @@ | |||
1 | export * from './process' | 1 | export * from './process' |
2 | export * from './send' | 2 | export * from './send' |
3 | export * from './actor' | 3 | export * from './actor' |
4 | export * from './fetch' | ||
5 | export * from './share' | 4 | export * from './share' |
6 | export * from './videos' | 5 | export * from './videos' |
7 | export * from './video-comments' | 6 | export * 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' | |||
5 | import { VideoModel } from '../../../models/video/video' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getOrCreateActorAndServerAndModel } from '../actor' | 7 | import { getOrCreateActorAndServerAndModel } from '../actor' |
8 | import { forwardActivity } from '../send/misc' | 8 | import { forwardActivity } from '../send/utils' |
9 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 9 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
10 | 10 | ||
11 | async function processAnnounceActivity (activity: ActivityAnnounce) { | 11 | async 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' | |||
9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
10 | import { VideoCommentModel } from '../../../models/video/video-comment' | 10 | import { VideoCommentModel } from '../../../models/video/video-comment' |
11 | import { getOrCreateActorAndServerAndModel } from '../actor' | 11 | import { getOrCreateActorAndServerAndModel } from '../actor' |
12 | import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc' | 12 | import { getActorsInvolvedInVideo } from '../audience' |
13 | import { resolveThread } from '../video-comments' | 13 | import { resolveThread } from '../video-comments' |
14 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 14 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
15 | import { forwardActivity } from '../send/utils' | ||
15 | 16 | ||
16 | async function processCreateActivity (activity: ActivityCreate) { | 17 | async 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' | |||
8 | import { VideoChannelModel } from '../../../models/video/video-channel' | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
9 | import { VideoCommentModel } from '../../../models/video/video-comment' | 9 | import { VideoCommentModel } from '../../../models/video/video-comment' |
10 | import { getOrCreateActorAndServerAndModel } from '../actor' | 10 | import { getOrCreateActorAndServerAndModel } from '../actor' |
11 | import { forwardActivity } from '../send/misc' | 11 | import { forwardActivity } from '../send/utils' |
12 | 12 | ||
13 | async function processDeleteActivity (activity: ActivityDelete) { | 13 | async 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' | |||
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { getOrCreateActorAndServerAndModel } from '../actor' | 6 | import { getOrCreateActorAndServerAndModel } from '../actor' |
7 | import { forwardActivity } from '../send/misc' | 7 | import { forwardActivity } from '../send/utils' |
8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
9 | 9 | ||
10 | async function processLikeActivity (activity: ActivityLike) { | 10 | async 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' | |||
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | 9 | import { ActorModel } from '../../../models/activitypub/actor' |
10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
11 | import { forwardActivity } from '../send/misc' | 11 | import { forwardActivity } from '../send/utils' |
12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | 13 | import { 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' | |||
14 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' | 14 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' |
15 | import { | 15 | import { |
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 | |||
2 | import { ActorModel } from '../../../models/activitypub/actor' | 2 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
4 | import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' | 4 | import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' |
5 | import { unicastTo } from './misc' | 5 | import { unicastTo } from './utils' |
6 | import { followActivityData } from './send-follow' | 6 | import { followActivityData } from './send-follow' |
7 | 7 | ||
8 | async function sendAccept (actorFollow: ActorFollowModel) { | 8 | async 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 | |||
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { VideoShareModel } from '../../../models/video/video-share' | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
6 | import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc' | 6 | import { broadcastToFollowers } from './utils' |
7 | import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience' | ||
7 | 8 | ||
8 | async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | 9 | async 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' | |||
7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 7 | 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 { broadcastToActors, broadcastToFollowers, unicastTo } from './utils' | ||
10 | import { | 11 | import { |
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 | ||
22 | async function sendCreateVideo (video: VideoModel, t: Transaction) { | 20 | async 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' | |||
5 | import { VideoCommentModel } from '../../../models/video/video-comment' | 5 | import { VideoCommentModel } from '../../../models/video/video-comment' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getDeleteActivityPubUrl } from '../url' | 7 | import { getDeleteActivityPubUrl } from '../url' |
8 | import { audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getVideoCommentAudience, unicastTo } from './misc' | 8 | import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils' |
9 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | ||
9 | 10 | ||
10 | async function sendDeleteVideo (video: VideoModel, t: Transaction) { | 11 | async 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' | |||
2 | import { ActorModel } from '../../../models/activitypub/actor' | 2 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
4 | import { getActorFollowActivityPubUrl } from '../url' | 4 | import { getActorFollowActivityPubUrl } from '../url' |
5 | import { unicastTo } from './misc' | 5 | import { unicastTo } from './utils' |
6 | 6 | ||
7 | function sendFollow (actorFollow: ActorFollowModel) { | 7 | function 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 | |||
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { getVideoLikeActivityPubUrl } from '../url' | 5 | import { getVideoLikeActivityPubUrl } from '../url' |
6 | import { | 6 | import { broadcastToFollowers, unicastTo } from './utils' |
7 | audiencify, | 7 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' |
8 | broadcastToFollowers, | ||
9 | getActorsInvolvedInVideo, | ||
10 | getAudience, | ||
11 | getObjectFollowersAudience, | ||
12 | getOriginVideoAudience, | ||
13 | unicastTo | ||
14 | } from './misc' | ||
15 | 8 | ||
16 | async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) { | 9 | async 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' | |||
11 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 11 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
12 | import { VideoModel } from '../../../models/video/video' | 12 | import { VideoModel } from '../../../models/video/video' |
13 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 13 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' |
14 | import { | 14 | import { broadcastToFollowers, unicastTo } from './utils' |
15 | audiencify, | 15 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' |
16 | broadcastToFollowers, | ||
17 | getActorsInvolvedInVideo, | ||
18 | getAudience, | ||
19 | getObjectFollowersAudience, | ||
20 | getOriginVideoAudience, | ||
21 | unicastTo | ||
22 | } from './misc' | ||
23 | import { createActivityData, createDislikeActivityData } from './send-create' | 16 | import { createActivityData, createDislikeActivityData } from './send-create' |
24 | import { followActivityData } from './send-follow' | 17 | import { followActivityData } from './send-follow' |
25 | import { likeActivityData } from './send-like' | 18 | import { 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' | |||
7 | import { VideoChannelModel } from '../../../models/video/video-channel' | 7 | import { VideoChannelModel } from '../../../models/video/video-channel' |
8 | import { VideoShareModel } from '../../../models/video/video-share' | 8 | import { VideoShareModel } from '../../../models/video/video-share' |
9 | import { getUpdateActivityPubUrl } from '../url' | 9 | import { getUpdateActivityPubUrl } from '../url' |
10 | import { audiencify, broadcastToFollowers, getAudience } from './misc' | 10 | import { broadcastToFollowers } from './utils' |
11 | import { audiencify, getAudience } from '../audience' | ||
11 | 12 | ||
12 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { | 13 | async 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' | 2 | import { Activity } from '../../../../shared/models/activitypub' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { ACTIVITY_PUB } from '../../../initializers' | ||
5 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
7 | import { VideoModel } from '../../../models/video/video' | ||
8 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
9 | import { VideoShareModel } from '../../../models/video/video-share' | ||
10 | import { JobQueue } from '../../job-queue' | 6 | import { JobQueue } from '../../job-queue' |
11 | 7 | ||
12 | async function forwardActivity ( | 8 | async 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 | ||
92 | function 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 | |||
99 | function 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 | |||
127 | function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { | ||
128 | return { | ||
129 | to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), | ||
130 | cc: [] | ||
131 | } | ||
132 | } | ||
133 | |||
134 | async 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 | |||
141 | async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { | ||
142 | return buildAudience([ actorSender.followersUrl ], isPublic) | ||
143 | } | ||
144 | |||
145 | function 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 } | 90 | export { |
91 | broadcastToFollowers, | ||
92 | unicastTo, | ||
93 | forwardActivity, | ||
94 | broadcastToActors | ||
159 | } | 95 | } |
160 | 96 | ||
161 | function audiencify <T> (object: T, audience: ActivityAudience) { | 97 | // --------------------------------------------------------------------------- |
162 | return Object.assign(object, audience) | ||
163 | } | ||
164 | 98 | ||
165 | async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) { | 99 | async 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 | |||
183 | export { | ||
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 | } |