From 54141398354e6e7b94aa3065a705a1251390111c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 20 Nov 2017 09:43:39 +0100 Subject: Refractor activity pub lib/helpers --- server/lib/activitypub/process-follow.ts | 57 -------------------------------- 1 file changed, 57 deletions(-) delete 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 deleted file mode 100644 index a805c0757..000000000 --- a/server/lib/activitypub/process-follow.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { ActivityFollow } from '../../../shared/models/activitypub/activity' -import { getOrCreateAccount, retryTransactionWrapper } from '../../helpers' -import { database as db } from '../../initializers' -import { AccountInstance } from '../../models/account/account-interface' -import { sendAccept } from './send-request' -import { logger } from '../../helpers/logger' - -async function processFollowActivity (activity: ActivityFollow) { - const activityObject = activity.object - const account = await getOrCreateAccount(activity.actor) - - return processFollow(account, activityObject) -} - -// --------------------------------------------------------------------------- - -export { - processFollowActivity -} - -// --------------------------------------------------------------------------- - -function processFollow (account: AccountInstance, targetAccountURL: string) { - const options = { - arguments: [ account, targetAccountURL ], - errorMessage: 'Cannot follow with many retries.' - } - - return retryTransactionWrapper(follow, options) -} - -async function follow (account: AccountInstance, targetAccountURL: string) { - await db.sequelize.transaction(async t => { - const targetAccount = await db.Account.loadByUrl(targetAccountURL, t) - - if (targetAccount === undefined) throw new Error('Unknown account') - if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') - - await db.AccountFollow.findOrCreate({ - where: { - accountId: account.id, - targetAccountId: targetAccount.id - }, - defaults: { - accountId: account.id, - targetAccountId: targetAccount.id, - state: 'accepted' - }, - transaction: t - }) - - // Target sends to account he accepted the follow request - return sendAccept(targetAccount, account, t) - }) - - logger.info('Account uuid %s is followed by account %s.', account.url, targetAccountURL) -} -- cgit v1.2.3