aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/activitypub-follow.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/activitypub-follow.ts')
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index 741b1ffde..5cb55cad6 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -10,7 +10,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
10import { ActorModel } from '../../../models/activitypub/actor' 10import { ActorModel } from '../../../models/activitypub/actor'
11import { Notifier } from '../../notifier' 11import { Notifier } from '../../notifier'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MActorFollowFull, MActorFull } from '../../../typings/models' 13import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models'
14 14
15export type ActivitypubFollowPayload = { 15export type ActivitypubFollowPayload = {
16 followerActorId: number 16 followerActorId: number
@@ -45,7 +45,7 @@ export {
45 45
46// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
47 47
48async function follow (fromActor: MActorFull, targetActor: MActorFull) { 48async function follow (fromActor: MActor, targetActor: MActorFull) {
49 if (fromActor.id === targetActor.id) { 49 if (fromActor.id === targetActor.id) {
50 throw new Error('Follower is the same than target actor.') 50 throw new Error('Follower is the same than target actor.')
51 } 51 }
@@ -54,7 +54,7 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
54 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' 54 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
55 55
56 const actorFollow = await sequelizeTypescript.transaction(async t => { 56 const actorFollow = await sequelizeTypescript.transaction(async t => {
57 const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowFull>({ 57 const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({
58 where: { 58 where: {
59 actorId: fromActor.id, 59 actorId: fromActor.id,
60 targetActorId: targetActor.id 60 targetActorId: targetActor.id
@@ -75,5 +75,14 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
75 return actorFollow 75 return actorFollow
76 }) 76 })
77 77
78 if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollow) 78 if (actorFollow.state === 'accepted') {
79 const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount })
80
81 const actorFollowFull = Object.assign(actorFollow, {
82 ActorFollowing: targetActor,
83 ActorFollower: followerFull
84 })
85
86 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
87 }
79} 88}