From 4bbc373f134ecbf53f0198277663a25b26a19cc8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jan 2018 17:37:49 +0100 Subject: Add reject processing for activitypub --- server/lib/activitypub/process/process-reject.ts | 32 ++++++++++++++++++++++++ server/lib/activitypub/process/process.ts | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 server/lib/activitypub/process/process-reject.ts (limited to 'server/lib') diff --git a/server/lib/activitypub/process/process-reject.ts b/server/lib/activitypub/process/process-reject.ts new file mode 100644 index 000000000..b2de28d79 --- /dev/null +++ b/server/lib/activitypub/process/process-reject.ts @@ -0,0 +1,32 @@ +import { ActivityReject } from '../../../../shared/models/activitypub/activity' +import { sequelizeTypescript } from '../../../initializers' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' + +async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) { + if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.') + + const targetActor = await ActorModel.loadByUrl(activity.actor) + + return processReject(inboxActor, targetActor) +} + +// --------------------------------------------------------------------------- + +export { + processRejectActivity +} + +// --------------------------------------------------------------------------- + +async function processReject (actor: ActorModel, targetActor: ActorModel) { + return sequelizeTypescript.transaction(async t => { + const actorFollow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id, t) + + if (!actorFollow) throw new Error(`'Unknown actor follow ${actor.id} -> ${targetActor.id}.`) + + await actorFollow.destroy({ transaction: t }) + + return undefined + }) +} diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 62d310f21..810c28e26 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts @@ -7,6 +7,7 @@ import { processCreateActivity } from './process-create' import { processDeleteActivity } from './process-delete' import { processFollowActivity } from './process-follow' import { processLikeActivity } from './process-like' +import { processRejectActivity } from './process-reject' import { processUndoActivity } from './process-undo' import { processUpdateActivity } from './process-update' @@ -16,6 +17,7 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor? Delete: processDeleteActivity, Follow: processFollowActivity, Accept: processAcceptActivity, + Reject: processRejectActivity, Announce: processAnnounceActivity, Undo: processUndoActivity, Like: processLikeActivity -- cgit v1.2.3