2017-11-20 09:43:39 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityFollow } from '../../../../shared/models/activitypub/activity'
|
|
|
|
import { AccountInstance } from '../../../models'
|
|
|
|
import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
|
2017-11-20 10:24:29 +01:00
|
|
|
import { getAccountFollowActivityPubUrl } from '../url'
|
2017-11-20 09:43:39 +01:00
|
|
|
import { unicastTo } from './misc'
|
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
|
2017-11-20 09:43:39 +01:00
|
|
|
const me = accountFollow.AccountFollower
|
|
|
|
const following = accountFollow.AccountFollowing
|
|
|
|
|
|
|
|
const url = getAccountFollowActivityPubUrl(accountFollow)
|
2017-11-30 11:31:15 +01:00
|
|
|
const data = followActivityData(url, me, following)
|
2017-11-20 09:43:39 +01:00
|
|
|
|
|
|
|
return unicastTo(data, me, following.inboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
|
2017-11-20 09:43:39 +01:00
|
|
|
const activity: ActivityFollow = {
|
|
|
|
type: 'Follow',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
object: targetAccount.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendFollow,
|
|
|
|
followActivityData
|
|
|
|
}
|