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