1
0
Fork 0
peertube/server/lib/activitypub/send/send-follow.ts

35 lines
1 KiB
TypeScript
Raw Normal View History

2017-11-20 03:43:39 -05:00
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'
2017-11-20 03:43:39 -05:00
import { unicastTo } from './misc'
function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
2017-11-20 03:43:39 -05:00
const me = accountFollow.AccountFollower
const following = accountFollow.AccountFollowing
const url = getAccountFollowActivityPubUrl(accountFollow)
const data = followActivityData(url, me, following)
2017-11-20 03:43:39 -05:00
return unicastTo(data, me, following.inboxUrl, t)
}
function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
2017-11-20 03:43:39 -05:00
const activity: ActivityFollow = {
type: 'Follow',
id: url,
actor: byAccount.url,
object: targetAccount.url
}
return activity
}
// ---------------------------------------------------------------------------
export {
sendFollow,
followActivityData
}