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

33 lines
998 B
TypeScript
Raw Normal View History

2017-11-20 09:43:39 +01:00
import { Transaction } from 'sequelize'
2017-12-12 17:53:50 +01:00
import { ActivityFollow } from '../../../../shared/models/activitypub'
2017-12-14 17:38:41 +01:00
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { getActorFollowActivityPubUrl } from '../url'
2017-11-20 09:43:39 +01:00
import { unicastTo } from './misc'
2017-12-14 17:38:41 +01:00
function sendFollow (actorFollow: ActorFollowModel, t: Transaction) {
const me = actorFollow.ActorFollower
const following = actorFollow.ActorFollowing
2017-11-20 09:43:39 +01:00
2017-12-14 17:38:41 +01:00
const url = getActorFollowActivityPubUrl(actorFollow)
const data = followActivityData(url, me, following)
2017-11-20 09:43:39 +01:00
return unicastTo(data, me, following.inboxUrl, t)
}
2017-12-14 17:38:41 +01:00
function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
2017-12-12 17:53:50 +01:00
return {
2017-11-20 09:43:39 +01:00
type: 'Follow',
id: url,
2017-12-14 17:38:41 +01:00
actor: byActor.url,
object: targetActor.url
2017-11-20 09:43:39 +01:00
}
}
// ---------------------------------------------------------------------------
export {
sendFollow,
followActivityData
}