PeerTube/server/lib/activitypub/audience.ts

35 lines
831 B
TypeScript
Raw Normal View History

2018-05-25 11:32:36 +02:00
import { ActivityAudience } from '../../../shared/models/activitypub'
import { ACTIVITY_PUB } from '../../initializers/constants'
import { MActorFollowersUrl } from '../../types/models'
2018-05-25 11:32:36 +02:00
2019-08-15 11:53:26 +02:00
function getAudience (actorSender: MActorFollowersUrl, isPublic = true) {
2018-05-25 11:32:36 +02:00
return buildAudience([ actorSender.followersUrl ], isPublic)
}
2018-05-28 12:13:00 +02:00
function buildAudience (followerUrls: string[], isPublic = true) {
let to: string[] = []
let cc: string[] = []
2018-05-25 11:32:36 +02:00
if (isPublic) {
to = [ ACTIVITY_PUB.PUBLIC ]
2018-05-28 12:13:00 +02:00
cc = followerUrls
2018-05-25 11:32:36 +02:00
} else { // Unlisted
to = []
cc = []
2018-05-25 11:32:36 +02:00
}
return { to, cc }
}
function audiencify<T> (object: T, audience: ActivityAudience) {
2022-03-23 16:14:33 +01:00
return { ...audience, ...object }
2018-05-25 11:32:36 +02:00
}
// ---------------------------------------------------------------------------
export {
buildAudience,
getAudience,
audiencify
2018-05-25 11:32:36 +02:00
}