aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-reject.ts
blob: 83d8dfba72366e78888216535a0aec006b2c32de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { ActivityFollow, ActivityReject } from '@shared/models'
import { logger } from '../../../helpers/logger'
import { MActor } from '../../../types/models'
import { getLocalActorFollowRejectActivityPubUrl } from '../url'
import { buildFollowActivity } from './send-follow'
import { unicastTo } from './shared/send-utils'

function sendReject (followUrl: string, follower: MActor, following: MActor) {
  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)

  const followData = buildFollowActivity(followUrl, follower, following)

  const url = getLocalActorFollowRejectActivityPubUrl(follower, following)
  const data = buildRejectActivity(url, following, followData)

  return unicastTo({ data, byActor: following, toActorUrl: follower.inboxUrl, contextType: 'Reject' })
}

// ---------------------------------------------------------------------------

export {
  sendReject
}

// ---------------------------------------------------------------------------

function buildRejectActivity (url: string, byActor: MActor, followActivityData: ActivityFollow): ActivityReject {
  return {
    type: 'Reject',
    id: url,
    actor: byActor.url,
    object: followActivityData
  }
}