]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/audience.ts
Fix playlist more button with long video names
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / audience.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { ActivityAudience } from '../../../shared/models/activitypub'
3import { ACTIVITY_PUB } from '../../initializers/constants'
4import { ActorModel } from '../../models/activitypub/actor'
5import { VideoModel } from '../../models/video/video'
6import { VideoCommentModel } from '../../models/video/video-comment'
7import { VideoShareModel } from '../../models/video/video-share'
8import { ActorModelOnly } from '../../typings/models'
9
10function getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience {
11 return {
12 to: [ video.VideoChannel.Account.Actor.url ],
13 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
14 }
15}
16
17function getVideoCommentAudience (
18 videoComment: VideoCommentModel,
19 threadParentComments: VideoCommentModel[],
20 actorsInvolvedInVideo: ActorModel[],
21 isOrigin = false
22): ActivityAudience {
23 const to = [ ACTIVITY_PUB.PUBLIC ]
24 const cc: string[] = []
25
26 // Owner of the video we comment
27 if (isOrigin === false) {
28 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
29 }
30
31 // Followers of the poster
32 cc.push(videoComment.Account.Actor.followersUrl)
33
34 // Send to actors we reply to
35 for (const parentComment of threadParentComments) {
36 cc.push(parentComment.Account.Actor.url)
37 }
38
39 return {
40 to,
41 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
42 }
43}
44
45function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): ActivityAudience {
46 return {
47 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
48 cc: []
49 }
50}
51
52async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
53 const actors = await VideoShareModel.loadActorsByShare(video.id, t)
54
55 const videoActor = video.VideoChannel && video.VideoChannel.Account
56 ? video.VideoChannel.Account.Actor
57 : await ActorModel.loadAccountActorByVideoId(video.id, t)
58
59 actors.push(videoActor)
60
61 return actors
62}
63
64function getAudience (actorSender: ActorModelOnly, isPublic = true) {
65 return buildAudience([ actorSender.followersUrl ], isPublic)
66}
67
68function buildAudience (followerUrls: string[], isPublic = true) {
69 let to: string[] = []
70 let cc: string[] = []
71
72 if (isPublic) {
73 to = [ ACTIVITY_PUB.PUBLIC ]
74 cc = followerUrls
75 } else { // Unlisted
76 to = []
77 cc = []
78 }
79
80 return { to, cc }
81}
82
83function audiencify<T> (object: T, audience: ActivityAudience) {
84 return Object.assign(object, audience)
85}
86
87// ---------------------------------------------------------------------------
88
89export {
90 buildAudience,
91 getAudience,
92 getRemoteVideoAudience,
93 getActorsInvolvedInVideo,
94 getAudienceFromFollowersOf,
95 audiencify,
96 getVideoCommentAudience
97}