From 7a7724e66e4533523083e7336cd0d0c747c4a33b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 13 Nov 2017 17:39:41 +0100 Subject: Handle follow/accept --- server/lib/activitypub/process-follow.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/lib/activitypub/process-follow.ts (limited to 'server/lib/activitypub/process-follow.ts') diff --git a/server/lib/activitypub/process-follow.ts b/server/lib/activitypub/process-follow.ts new file mode 100644 index 000000000..a04fc7994 --- /dev/null +++ b/server/lib/activitypub/process-follow.ts @@ -0,0 +1,32 @@ +import { ActivityFollow } from '../../../shared/models/activitypub/activity' +import { getOrCreateAccount } from '../../helpers' +import { database as db } from '../../initializers' +import { AccountInstance } from '../../models/account/account-interface' + +async function processFollowActivity (activity: ActivityFollow) { + const activityObject = activity.object + const account = await getOrCreateAccount(activity.actor) + + return processFollow(account, activityObject) +} + +// --------------------------------------------------------------------------- + +export { + processFollowActivity +} + +// --------------------------------------------------------------------------- + +async function processFollow (account: AccountInstance, targetAccountURL: string) { + const targetAccount = await db.Account.loadByUrl(targetAccountURL) + + if (targetAccount === undefined) throw new Error('Unknown account') + if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') + + return db.AccountFollow.create({ + accountId: account.id, + targetAccountId: targetAccount.id, + state: 'accepted' + }) +} -- cgit v1.2.3