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

41 lines
1.4 KiB
TypeScript
Raw Normal View History

import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
2019-04-08 08:04:57 -04:00
import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url'
import { unicastTo } from './utils'
import { buildFollowActivity } from './send-follow'
import { logger } from '../../../helpers/logger'
2019-04-08 08:04:57 -04:00
async function sendReject (follower: ActorModel, following: ActorModel) {
if (!follower.serverId) { // This should never happen
logger.warn('Do not sending reject to local follower.')
return
}
logger.info('Creating job to reject follower %s.', follower.url)
2019-04-08 08:04:57 -04:00
const followUrl = getActorFollowActivityPubUrl(follower, following)
const followData = buildFollowActivity(followUrl, follower, following)
2019-04-08 08:04:57 -04:00
const url = getActorFollowRejectActivityPubUrl(follower, following)
const data = buildRejectActivity(url, following, followData)
2019-04-08 08:04:57 -04:00
return unicastTo(data, following, follower.inboxUrl)
}
// ---------------------------------------------------------------------------
export {
sendReject
}
// ---------------------------------------------------------------------------
function buildRejectActivity (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityReject {
return {
type: 'Reject',
id: url,
actor: byActor.url,
object: followActivityData
}
}