]>
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' | |
5224c394 | 8 | import { ActorModelOnly } from '../../typings/models' |
e251f170 | 9 | |
a2377d15 | 10 | function getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience { |
e251f170 C |
11 | return { |
12 | to: [ video.VideoChannel.Account.Actor.url ], | |
13 | cc: actorsInvolvedInVideo.map(a => a.followersUrl) | |
14 | } | |
15 | } | |
16 | ||
17 | function getVideoCommentAudience ( | |
18 | videoComment: VideoCommentModel, | |
19 | threadParentComments: VideoCommentModel[], | |
20 | actorsInvolvedInVideo: ActorModel[], | |
21 | isOrigin = false | |
a2377d15 | 22 | ): ActivityAudience { |
e251f170 | 23 | const to = [ ACTIVITY_PUB.PUBLIC ] |
c1e791ba | 24 | const cc: string[] = [] |
e251f170 C |
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 | ||
a2377d15 | 45 | function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): ActivityAudience { |
e251f170 C |
46 | return { |
47 | to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), | |
48 | cc: [] | |
49 | } | |
50 | } | |
51 | ||
52 | async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { | |
53 | const actors = await VideoShareModel.loadActorsByShare(video.id, t) | |
e5565833 C |
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) | |
e251f170 C |
60 | |
61 | return actors | |
62 | } | |
63 | ||
5224c394 | 64 | function getAudience (actorSender: ActorModelOnly, isPublic = true) { |
e251f170 C |
65 | return buildAudience([ actorSender.followersUrl ], isPublic) |
66 | } | |
67 | ||
e3d5ea4f | 68 | function buildAudience (followerUrls: string[], isPublic = true) { |
c1e791ba RK |
69 | let to: string[] = [] |
70 | let cc: string[] = [] | |
e251f170 C |
71 | |
72 | if (isPublic) { | |
73 | to = [ ACTIVITY_PUB.PUBLIC ] | |
e3d5ea4f | 74 | cc = followerUrls |
e251f170 | 75 | } else { // Unlisted |
2186386c C |
76 | to = [] |
77 | cc = [] | |
e251f170 C |
78 | } |
79 | ||
80 | return { to, cc } | |
81 | } | |
82 | ||
2186386c | 83 | function audiencify<T> (object: T, audience: ActivityAudience) { |
e251f170 C |
84 | return Object.assign(object, audience) |
85 | } | |
86 | ||
87 | // --------------------------------------------------------------------------- | |
88 | ||
89 | export { | |
90 | buildAudience, | |
91 | getAudience, | |
a2377d15 | 92 | getRemoteVideoAudience, |
e251f170 | 93 | getActorsInvolvedInVideo, |
a2377d15 | 94 | getAudienceFromFollowersOf, |
e251f170 C |
95 | audiencify, |
96 | getVideoCommentAudience | |
97 | } |