aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 15:25:20 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch)
treeac197f3ed0768529456225ad76c912f22bc55e29 /server/lib/activitypub
parent4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff)
downloadPeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/actor.ts2
-rw-r--r--server/lib/activitypub/send/send-accept.ts5
-rw-r--r--server/lib/activitypub/send/send-create.ts2
-rw-r--r--server/lib/activitypub/send/send-follow.ts3
-rw-r--r--server/lib/activitypub/send/send-undo.ts3
-rw-r--r--server/lib/activitypub/send/utils.ts21
6 files changed, 32 insertions, 4 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index b67d9f08b..d84b465b2 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -352,7 +352,7 @@ async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> {
352 if (!actor.isOutdated()) return actor 352 if (!actor.isOutdated()) return actor
353 353
354 try { 354 try {
355 const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost()) 355 const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost())
356 const result = await fetchRemoteActor(actorUrl) 356 const result = await fetchRemoteActor(actorUrl)
357 if (result === undefined) { 357 if (result === undefined) {
358 logger.warn('Cannot fetch remote actor in refresh actor.') 358 logger.warn('Cannot fetch remote actor in refresh actor.')
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
35async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { 35async 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'
6import { JobQueue } from '../../job-queue' 6import { JobQueue } from '../../job-queue'
7import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
8import { getActorsInvolvedInVideo } from '../audience' 8import { getActorsInvolvedInVideo } from '../audience'
9import { getServerActor } from '../../../helpers/utils'
9 10
10async function forwardVideoRelatedActivity ( 11async 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
125async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) { 127async 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
140async 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}