aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/activitypub/send/send-follow.ts
blob: 51735ddfd0599569b4079c722b5cff27f2602f71 (plain) (tree)
1
2
3
4
5
6
7
8
                                       


                                                                           
                                                       
                                  
 
                                                                         



                                                           
                                                     



                                                   

                                                                                                                 




                             







                                                                              
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
}