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/send/send-follow.ts | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/lib/activitypub/send/send-follow.ts (limited to 'server/lib/activitypub/send/send-follow.ts') diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts new file mode 100644 index 000000000..48d641c22 --- /dev/null +++ b/server/lib/activitypub/send/send-follow.ts @@ -0,0 +1,34 @@ +import { Transaction } from 'sequelize' +import { ActivityFollow } from '../../../../shared/models/activitypub/activity' +import { AccountInstance } from '../../../models' +import { AccountFollowInstance } from '../../../models/account/account-follow-interface' +import { unicastTo } from './misc' +import { getAccountFollowActivityPubUrl } from '../../../helpers/activitypub' + +async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { + const me = accountFollow.AccountFollower + const following = accountFollow.AccountFollowing + + const url = getAccountFollowActivityPubUrl(accountFollow) + const data = await followActivityData(url, me, following) + + return unicastTo(data, me, following.inboxUrl, t) +} + +async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) { + const activity: ActivityFollow = { + type: 'Follow', + id: url, + actor: byAccount.url, + object: targetAccount.url + } + + return activity +} + +// --------------------------------------------------------------------------- + +export { + sendFollow, + followActivityData +} -- cgit v1.2.3