aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-follow.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-30 16:50:12 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-09-04 16:24:58 +0200
commit8424c4026afd7304880a4ce8138a04ffb3d8c938 (patch)
tree5b42625a59307b03333aa7d293b40b4c90da8f73 /server/lib/activitypub/process/process-follow.ts
parentf69ec5f340638ef577e8f5b9b1fb844778656a1f (diff)
downloadPeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.gz
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.zst
PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.zip
Add auto follow back support for instances
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r--server/lib/activitypub/process/process-follow.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index bc5660395..85f22d654 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -10,7 +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 { MAccount, MActorFollowActors, MActorFollowFull, MActorSignature } from '../../../typings/models' 13import { MActorFollowActors, MActorSignature } from '../../../typings/models'
14import { autoFollowBackIfNeeded } from '../follow'
14 15
15async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { 16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
16 const { activity, byActor } = options 17 const { activity, byActor } = options
@@ -28,7 +29,7 @@ export {
28// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
29 30
30async function processFollow (byActor: MActorSignature, targetActorURL: string) { 31async function processFollow (byActor: MActorSignature, targetActorURL: string) {
31 const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { 32 const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => {
32 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 33 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
33 34
34 if (!targetActor) throw new Error('Unknown actor') 35 if (!targetActor) throw new Error('Unknown actor')
@@ -67,21 +68,24 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string)
67 actorFollow.ActorFollowing = targetActor 68 actorFollow.ActorFollowing = targetActor
68 69
69 // Target sends to actor he accepted the follow request 70 // Target sends to actor he accepted the follow request
70 if (actorFollow.state === 'accepted') await sendAccept(actorFollow) 71 if (actorFollow.state === 'accepted') {
72 await sendAccept(actorFollow)
73 await autoFollowBackIfNeeded(actorFollow)
74 }
71 75
72 return { actorFollow, created, isFollowingInstance } 76 return { actorFollow, created, isFollowingInstance, targetActor }
73 }) 77 })
74 78
75 // Rejected 79 // Rejected
76 if (!actorFollow) return 80 if (!actorFollow) return
77 81
78 if (created) { 82 if (created) {
83 const follower = await ActorModel.loadFull(byActor.id)
84 const actorFollowFull = Object.assign(actorFollow, { ActorFollowing: targetActor, ActorFollower: follower })
85
79 if (isFollowingInstance) { 86 if (isFollowingInstance) {
80 Notifier.Instance.notifyOfNewInstanceFollow(actorFollow) 87 Notifier.Instance.notifyOfNewInstanceFollow(actorFollowFull)
81 } else { 88 } else {
82 const actorFollowFull = actorFollow as MActorFollowFull
83 actorFollowFull.ActorFollower.Account = await actorFollow.ActorFollower.$get('Account') as MAccount
84
85 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) 89 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
86 } 90 }
87 } 91 }