2017-11-20 02:43:39 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-12-19 03:34:56 -06:00
|
|
|
import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
2017-12-19 03:34:56 -06:00
|
|
|
import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { unicastTo } from './misc'
|
2017-12-19 03:34:56 -06:00
|
|
|
import { followActivityData } from './send-follow'
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) {
|
|
|
|
const follower = actorFollow.ActorFollower
|
|
|
|
const me = actorFollow.ActorFollowing
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2017-12-19 03:34:56 -06:00
|
|
|
const followUrl = getActorFollowActivityPubUrl(actorFollow)
|
|
|
|
const followData = followActivityData(followUrl, follower, me)
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
const url = getActorFollowAcceptActivityPubUrl(actorFollow)
|
2017-12-19 03:34:56 -06:00
|
|
|
const data = acceptActivityData(url, me, followData)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
|
|
|
return unicastTo(data, me, follower.inboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendAccept
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-12-19 03:34:56 -06:00
|
|
|
function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
|
2017-12-14 10:38:41 -06:00
|
|
|
return {
|
2017-11-20 02:43:39 -06:00
|
|
|
type: 'Accept',
|
|
|
|
id: url,
|
2017-12-19 03:34:56 -06:00
|
|
|
actor: byActor.url,
|
|
|
|
object: followActivityData
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
}
|