diff options
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-accept.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index 89bda9c32..605705ad3 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts | |||
@@ -2,6 +2,7 @@ import { ActivityAccept } from '../../../../shared/models/activitypub' | |||
2 | import { ActorModel } from '../../../models/activitypub/actor' | 2 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
4 | import { addFetchOutboxJob } from '../actor' | 4 | import { addFetchOutboxJob } from '../actor' |
5 | import { Notifier } from '../../notifier' | ||
5 | 6 | ||
6 | async function processAcceptActivity (activity: ActivityAccept, targetActor: ActorModel, inboxActor?: ActorModel) { | 7 | async function processAcceptActivity (activity: ActivityAccept, targetActor: ActorModel, inboxActor?: ActorModel) { |
7 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') | 8 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') |
@@ -24,6 +25,7 @@ async function processAccept (actor: ActorModel, targetActor: ActorModel) { | |||
24 | if (follow.state !== 'accepted') { | 25 | if (follow.state !== 'accepted') { |
25 | follow.set('state', 'accepted') | 26 | follow.set('state', 'accepted') |
26 | await follow.save() | 27 | await follow.save() |
28 | |||
27 | await addFetchOutboxJob(targetActor) | 29 | await addFetchOutboxJob(targetActor) |
28 | } | 30 | } |
29 | } | 31 | } |
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 24c9085f7..a67892440 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -5,6 +5,7 @@ import { sequelizeTypescript } from '../../../initializers' | |||
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
7 | import { sendAccept } from '../send' | 7 | import { sendAccept } from '../send' |
8 | import { Notifier } from '../../notifier' | ||
8 | 9 | ||
9 | async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { | 10 | async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { |
10 | const activityObject = activity.object | 11 | const activityObject = activity.object |
@@ -21,13 +22,13 @@ export { | |||
21 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
22 | 23 | ||
23 | async function processFollow (actor: ActorModel, targetActorURL: string) { | 24 | async function processFollow (actor: ActorModel, targetActorURL: string) { |
24 | await sequelizeTypescript.transaction(async t => { | 25 | const { actorFollow, created } = await sequelizeTypescript.transaction(async t => { |
25 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) | 26 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) |
26 | 27 | ||
27 | if (!targetActor) throw new Error('Unknown actor') | 28 | if (!targetActor) throw new Error('Unknown actor') |
28 | if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') | 29 | if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') |
29 | 30 | ||
30 | const [ actorFollow ] = await ActorFollowModel.findOrCreate({ | 31 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ |
31 | where: { | 32 | where: { |
32 | actorId: actor.id, | 33 | actorId: actor.id, |
33 | targetActorId: targetActor.id | 34 | targetActorId: targetActor.id |
@@ -52,8 +53,12 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { | |||
52 | actorFollow.ActorFollowing = targetActor | 53 | actorFollow.ActorFollowing = targetActor |
53 | 54 | ||
54 | // Target sends to actor he accepted the follow request | 55 | // Target sends to actor he accepted the follow request |
55 | return sendAccept(actorFollow) | 56 | await sendAccept(actorFollow) |
57 | |||
58 | return { actorFollow, created } | ||
56 | }) | 59 | }) |
57 | 60 | ||
61 | if (created) Notifier.Instance.notifyOfNewFollow(actorFollow) | ||
62 | |||
58 | logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) | 63 | logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) |
59 | } | 64 | } |