aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts13
1 files changed, 9 insertions, 4 deletions
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 },