aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-follow.ts
blob: 8fba1b6b57661ca765714091bc2055f36512d19a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 { getAccountFollowActivityPubUrl } from '../url'
import { unicastTo } from './misc'

function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
  const me = accountFollow.AccountFollower
  const following = accountFollow.AccountFollowing

  const url = getAccountFollowActivityPubUrl(accountFollow)
  const data = followActivityData(url, me, following)

  return unicastTo(data, me, following.inboxUrl, t)
}

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
}