PeerTube/server/lib/activitypub/send/send-follow.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { Transaction } from 'sequelize'
2017-12-12 10:53:50 -06:00
import { ActivityFollow } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { AccountFollowModel } from '../../../models/account/account-follow'
import { getAccountFollowActivityPubUrl } from '../url'
2017-11-20 02:43:39 -06:00
import { unicastTo } from './misc'
2017-12-12 10:53:50 -06:00
function sendFollow (accountFollow: AccountFollowModel, t: Transaction) {
2017-11-20 02:43:39 -06:00
const me = accountFollow.AccountFollower
const following = accountFollow.AccountFollowing
const url = getAccountFollowActivityPubUrl(accountFollow)
const data = followActivityData(url, me, following)
2017-11-20 02:43:39 -06:00
return unicastTo(data, me, following.inboxUrl, t)
}
2017-12-12 10:53:50 -06:00
function followActivityData (url: string, byAccount: AccountModel, targetAccount: AccountModel): ActivityFollow {
return {
2017-11-20 02:43:39 -06:00
type: 'Follow',
id: url,
actor: byAccount.url,
object: targetAccount.url
}
}
// ---------------------------------------------------------------------------
export {
sendFollow,
followActivityData
}