diff options
Diffstat (limited to 'server/lib/activitypub/send/send-follow.ts')
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 34 |
1 files changed, 34 insertions, 0 deletions
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 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityFollow } from '../../../../shared/models/activitypub/activity' | ||
3 | import { AccountInstance } from '../../../models' | ||
4 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | ||
5 | import { unicastTo } from './misc' | ||
6 | import { getAccountFollowActivityPubUrl } from '../../../helpers/activitypub' | ||
7 | |||
8 | async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { | ||
9 | const me = accountFollow.AccountFollower | ||
10 | const following = accountFollow.AccountFollowing | ||
11 | |||
12 | const url = getAccountFollowActivityPubUrl(accountFollow) | ||
13 | const data = await followActivityData(url, me, following) | ||
14 | |||
15 | return unicastTo(data, me, following.inboxUrl, t) | ||
16 | } | ||
17 | |||
18 | async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) { | ||
19 | const activity: ActivityFollow = { | ||
20 | type: 'Follow', | ||
21 | id: url, | ||
22 | actor: byAccount.url, | ||
23 | object: targetAccount.url | ||
24 | } | ||
25 | |||
26 | return activity | ||
27 | } | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | export { | ||
32 | sendFollow, | ||
33 | followActivityData | ||
34 | } | ||