aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-follow.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r--server/lib/activitypub/process/process-follow.ts31
1 files changed, 20 insertions, 11 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 240aa5799..85f22d654 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -10,8 +10,8 @@ import { getAPId } from '../../../helpers/activitypub'
10import { getServerActor } from '../../../helpers/utils' 10import { getServerActor } from '../../../helpers/utils'
11import { CONFIG } from '../../../initializers/config' 11import { CONFIG } from '../../../initializers/config'
12import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 12import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
13import { SignatureActorModel } from '../../../typings/models' 13import { MActorFollowActors, MActorSignature } from '../../../typings/models'
14import { ActorFollowModelLight } from '../../../typings/models/actor-follow' 14import { autoFollowBackIfNeeded } from '../follow'
15 15
16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { 16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
17 const { activity, byActor } = options 17 const { activity, byActor } = options
@@ -28,8 +28,8 @@ export {
28 28
29// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
30 30
31async function processFollow (byActor: SignatureActorModel, targetActorURL: string) { 31async function processFollow (byActor: MActorSignature, targetActorURL: string) {
32 const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { 32 const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => {
33 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 33 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
34 34
35 if (!targetActor) throw new Error('Unknown actor') 35 if (!targetActor) throw new Error('Unknown actor')
@@ -43,10 +43,10 @@ async function processFollow (byActor: SignatureActorModel, targetActorURL: stri
43 43
44 await sendReject(byActor, targetActor) 44 await sendReject(byActor, targetActor)
45 45
46 return { actorFollow: undefined } 46 return { actorFollow: undefined as MActorFollowActors }
47 } 47 }
48 48
49 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ 49 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({
50 where: { 50 where: {
51 actorId: byActor.id, 51 actorId: byActor.id,
52 targetActorId: targetActor.id 52 targetActorId: targetActor.id
@@ -57,7 +57,7 @@ async function processFollow (byActor: SignatureActorModel, targetActorURL: stri
57 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' 57 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted'
58 }, 58 },
59 transaction: t 59 transaction: t
60 }) as [ ActorFollowModelLight, boolean ] 60 })
61 61
62 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) { 62 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) {
63 actorFollow.state = 'accepted' 63 actorFollow.state = 'accepted'
@@ -68,17 +68,26 @@ async function processFollow (byActor: SignatureActorModel, targetActorURL: stri
68 actorFollow.ActorFollowing = targetActor 68 actorFollow.ActorFollowing = targetActor
69 69
70 // Target sends to actor he accepted the follow request 70 // Target sends to actor he accepted the follow request
71 if (actorFollow.state === 'accepted') await sendAccept(actorFollow) 71 if (actorFollow.state === 'accepted') {
72 await sendAccept(actorFollow)
73 await autoFollowBackIfNeeded(actorFollow)
74 }
72 75
73 return { actorFollow, created, isFollowingInstance } 76 return { actorFollow, created, isFollowingInstance, targetActor }
74 }) 77 })
75 78
76 // Rejected 79 // Rejected
77 if (!actorFollow) return 80 if (!actorFollow) return
78 81
79 if (created) { 82 if (created) {
80 if (isFollowingInstance) Notifier.Instance.notifyOfNewInstanceFollow(actorFollow) 83 const follower = await ActorModel.loadFull(byActor.id)
81 else Notifier.Instance.notifyOfNewUserFollow(actorFollow) 84 const actorFollowFull = Object.assign(actorFollow, { ActorFollowing: targetActor, ActorFollower: follower })
85
86 if (isFollowingInstance) {
87 Notifier.Instance.notifyOfNewInstanceFollow(actorFollowFull)
88 } else {
89 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
90 }
82 } 91 }
83 92
84 logger.info('Actor %s is followed by actor %s.', targetActorURL, byActor.url) 93 logger.info('Actor %s is followed by actor %s.', targetActorURL, byActor.url)