aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-follow.ts
blob: 51735ddfd0599569b4079c722b5cff27f2602f71 (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
import { Transaction } from 'sequelize'
import { ActivityFollow } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { AccountFollowModel } from '../../../models/account/account-follow'
import { getAccountFollowActivityPubUrl } from '../url'
import { unicastTo } from './misc'

function sendFollow (accountFollow: AccountFollowModel, 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: AccountModel, targetAccount: AccountModel): ActivityFollow {
  return {
    type: 'Follow',
    id: url,
    actor: byAccount.url,
    object: targetAccount.url
  }
}

// ---------------------------------------------------------------------------

export {
  sendFollow,
  followActivityData
}