aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-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
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts13
7 files changed, 41 insertions, 8 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}
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index 393c6936c..282dde268 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -1,7 +1,7 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { getServerActor } from '../../../helpers/utils' 3import { getServerActor } from '../../../helpers/utils'
4import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' 4import { REMOTE_SCHEME, sequelizeTypescript } from '../../../initializers'
5import { sendFollow } from '../../activitypub/send' 5import { sendFollow } from '../../activitypub/send'
6import { sanitizeHost } from '../../../helpers/core-utils' 6import { sanitizeHost } from '../../../helpers/core-utils'
7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' 7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
@@ -11,6 +11,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
11import { ActorModel } from '../../../models/activitypub/actor' 11import { ActorModel } from '../../../models/activitypub/actor'
12 12
13export type ActivitypubFollowPayload = { 13export type ActivitypubFollowPayload = {
14 followerActorId: number
15 name: string
14 host: string 16 host: string
15} 17}
16 18
@@ -22,10 +24,10 @@ async function processActivityPubFollow (job: Bull.Job) {
22 24
23 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) 25 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP)
24 26
25 const actorUrl = await loadActorUrlOrGetFromWebfinger(SERVER_ACTOR_NAME, sanitizedHost) 27 const actorUrl = await loadActorUrlOrGetFromWebfinger(payload.name + '@' + sanitizedHost)
26 const targetActor = await getOrCreateActorAndServerAndModel(actorUrl) 28 const targetActor = await getOrCreateActorAndServerAndModel(actorUrl)
27 29
28 const fromActor = await getServerActor() 30 const fromActor = await ActorModel.load(payload.followerActorId)
29 31
30 return retryTransactionWrapper(follow, fromActor, targetActor) 32 return retryTransactionWrapper(follow, fromActor, targetActor)
31} 33}
@@ -42,6 +44,9 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) {
42 throw new Error('Follower is the same than target actor.') 44 throw new Error('Follower is the same than target actor.')
43 } 45 }
44 46
47 // Same server, direct accept
48 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
49
45 return sequelizeTypescript.transaction(async t => { 50 return sequelizeTypescript.transaction(async t => {
46 const [ actorFollow ] = await ActorFollowModel.findOrCreate({ 51 const [ actorFollow ] = await ActorFollowModel.findOrCreate({
47 where: { 52 where: {
@@ -49,7 +54,7 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) {
49 targetActorId: targetActor.id 54 targetActorId: targetActor.id
50 }, 55 },
51 defaults: { 56 defaults: {
52 state: 'pending', 57 state,
53 actorId: fromActor.id, 58 actorId: fromActor.id,
54 targetActorId: targetActor.id 59 targetActorId: targetActor.id
55 }, 60 },