aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/activitypub/audience.ts
blob: 6f54913875858aff5b10f5131282c2137248a34d (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                     
                                                           
                                                       
 
                                                                         


                                                              
                                                                  

                       


                                
                     
                      

           




                   
                                                                
                                   






                                                                              
            
 
import { ActivityAudience } from '../../../shared/models/activitypub'
import { ACTIVITY_PUB } from '../../initializers/constants'
import { MActorFollowersUrl } from '../../types/models'

function getAudience (actorSender: MActorFollowersUrl, isPublic = true) {
  return buildAudience([ actorSender.followersUrl ], isPublic)
}

function buildAudience (followerUrls: string[], isPublic = true) {
  let to: string[] = []
  let cc: string[] = []

  if (isPublic) {
    to = [ ACTIVITY_PUB.PUBLIC ]
    cc = followerUrls
  } else { // Unlisted
    to = []
    cc = []
  }

  return { to, cc }
}

function audiencify<T> (object: T, audience: ActivityAudience) {
  return { ...audience, ...object }
}

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

export {
  buildAudience,
  getAudience,
  audiencify
}