diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-16 15:25:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | 06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch) | |
tree | ac197f3ed0768529456225ad76c912f22bc55e29 /server/lib/activitypub/send | |
parent | 4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff) | |
download | PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip |
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 21 |
5 files changed, 31 insertions, 3 deletions
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index dfee1ec3e..ef679707b 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts | |||
@@ -10,6 +10,11 @@ async function sendAccept (actorFollow: ActorFollowModel) { | |||
10 | const follower = actorFollow.ActorFollower | 10 | const follower = actorFollow.ActorFollower |
11 | const me = actorFollow.ActorFollowing | 11 | const me = actorFollow.ActorFollowing |
12 | 12 | ||
13 | if (!follower.serverId) { // This should never happen | ||
14 | logger.warn('Do not sending accept to local follower.') | ||
15 | return | ||
16 | } | ||
17 | |||
13 | logger.info('Creating job to accept follower %s.', follower.url) | 18 | logger.info('Creating job to accept follower %s.', follower.url) |
14 | 19 | ||
15 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 20 | const followUrl = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index f7a8cf0b3..fc76cdd8a 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -33,6 +33,8 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { | 35 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
36 | if (!video.VideoChannel.Account.Actor.serverId) return // Local | ||
37 | |||
36 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 38 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
37 | 39 | ||
38 | logger.info('Creating job to send video abuse %s.', url) | 40 | logger.info('Creating job to send video abuse %s.', url) |
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 2faffe6e7..46d08c17b 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts | |||
@@ -9,6 +9,9 @@ function sendFollow (actorFollow: ActorFollowModel) { | |||
9 | const me = actorFollow.ActorFollower | 9 | const me = actorFollow.ActorFollower |
10 | const following = actorFollow.ActorFollowing | 10 | const following = actorFollow.ActorFollowing |
11 | 11 | ||
12 | // Same server as ours | ||
13 | if (!following.serverId) return | ||
14 | |||
12 | logger.info('Creating job to send follow request to %s.', following.url) | 15 | logger.info('Creating job to send follow request to %s.', following.url) |
13 | 16 | ||
14 | const url = getActorFollowActivityPubUrl(actorFollow) | 17 | const url = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 4e5dd3973..30d0fd98b 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -24,6 +24,9 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
24 | const me = actorFollow.ActorFollower | 24 | const me = actorFollow.ActorFollower |
25 | const following = actorFollow.ActorFollowing | 25 | const following = actorFollow.ActorFollowing |
26 | 26 | ||
27 | // Same server as ours | ||
28 | if (!following.serverId) return | ||
29 | |||
27 | logger.info('Creating job to send an unfollow request to %s.', following.url) | 30 | logger.info('Creating job to send an unfollow request to %s.', following.url) |
28 | 31 | ||
29 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 32 | const followUrl = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 0d28444ec..da437292e 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -6,6 +6,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
6 | import { JobQueue } from '../../job-queue' | 6 | import { JobQueue } from '../../job-queue' |
7 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { getActorsInvolvedInVideo } from '../audience' | 8 | import { getActorsInvolvedInVideo } from '../audience' |
9 | import { getServerActor } from '../../../helpers/utils' | ||
9 | 10 | ||
10 | async function forwardVideoRelatedActivity ( | 11 | async function forwardVideoRelatedActivity ( |
11 | activity: Activity, | 12 | activity: Activity, |
@@ -118,14 +119,28 @@ async function computeFollowerUris (toActorFollower: ActorModel[], actorsExcepti | |||
118 | const toActorFollowerIds = toActorFollower.map(a => a.id) | 119 | const toActorFollowerIds = toActorFollower.map(a => a.id) |
119 | 120 | ||
120 | const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) | 121 | const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) |
121 | const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl) | 122 | const sharedInboxesException = await buildSharedInboxesException(actorsException) |
123 | |||
122 | return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) | 124 | return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) |
123 | } | 125 | } |
124 | 126 | ||
125 | async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) { | 127 | async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) { |
126 | const toActorSharedInboxesSet = new Set(toActors.map(a => a.sharedInboxUrl || a.inboxUrl)) | 128 | const serverActor = await getServerActor() |
129 | const targetUrls = toActors | ||
130 | .filter(a => a.id !== serverActor.id) // Don't send to ourselves | ||
131 | .map(a => a.sharedInboxUrl || a.inboxUrl) | ||
132 | |||
133 | const toActorSharedInboxesSet = new Set(targetUrls) | ||
127 | 134 | ||
128 | const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl) | 135 | const sharedInboxesException = await buildSharedInboxesException(actorsException) |
129 | return Array.from(toActorSharedInboxesSet) | 136 | return Array.from(toActorSharedInboxesSet) |
130 | .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) | 137 | .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) |
131 | } | 138 | } |
139 | |||
140 | async function buildSharedInboxesException (actorsException: ActorModel[]) { | ||
141 | const serverActor = await getServerActor() | ||
142 | |||
143 | return actorsException | ||
144 | .map(f => f.sharedInboxUrl || f.inboxUrl) | ||
145 | .concat([ serverActor.sharedInboxUrl ]) | ||
146 | } | ||