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