]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
3fd3ab2d | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
50d6de9c C |
3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { getServerActor } from '../../../helpers' | |
5 | import { ActorModel } from '../../../models/activitypub/actor' | |
3fd3ab2d C |
6 | import { VideoModel } from '../../../models/video/video' |
7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | |
0032ebe9 C |
8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
9 | import { | |
10 | broadcastToFollowers, | |
50d6de9c | 11 | getActorsInvolvedInVideo, |
0032ebe9 | 12 | getAudience, |
4e50b6a1 | 13 | getObjectFollowersAudience, |
25ed141c | 14 | getOriginVideoAudience, |
0032ebe9 C |
15 | unicastTo |
16 | } from './misc' | |
54141398 | 17 | |
50d6de9c C |
18 | async function sendCreateVideo (video: VideoModel, t: Transaction) { |
19 | const byActor = video.VideoChannel.Account.Actor | |
54141398 | 20 | |
50d6de9c C |
21 | const videoObject = video.toActivityPubObject() |
22 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) | |
23 | const data = await createActivityData(video.url, byActor, videoObject, t, audience) | |
54141398 | 24 | |
50d6de9c | 25 | return broadcastToFollowers(data, byActor, [ byActor ], t) |
54141398 C |
26 | } |
27 | ||
50d6de9c | 28 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
54141398 | 29 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
40ff5707 | 30 | |
50d6de9c C |
31 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } |
32 | const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience) | |
40ff5707 | 33 | |
50d6de9c | 34 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
40ff5707 C |
35 | } |
36 | ||
50d6de9c C |
37 | async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
38 | const url = getVideoViewActivityPubUrl(byActor, video) | |
39 | const viewActivity = createViewActivityData(byActor, video) | |
40ff5707 | 40 | |
50d6de9c C |
41 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
42 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | |
43 | const data = await createActivityData(url, byActor, viewActivity, t, audience) | |
54141398 | 44 | |
50d6de9c | 45 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
54141398 C |
46 | } |
47 | ||
50d6de9c C |
48 | async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
49 | const url = getVideoViewActivityPubUrl(byActor, video) | |
50 | const viewActivity = createViewActivityData(byActor, video) | |
40ff5707 | 51 | |
50d6de9c C |
52 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
53 | const audience = getObjectFollowersAudience(actorsToForwardView) | |
54 | const data = await createActivityData(url, byActor, viewActivity, t, audience) | |
40ff5707 | 55 | |
50d6de9c C |
56 | // Use the server actor to send the view |
57 | const serverActor = await getServerActor() | |
58 | const followersException = [ byActor ] | |
59 | return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) | |
0032ebe9 C |
60 | } |
61 | ||
50d6de9c C |
62 | async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
63 | const url = getVideoDislikeActivityPubUrl(byActor, video) | |
64 | const dislikeActivity = createDislikeActivityData(byActor, video) | |
0032ebe9 | 65 | |
50d6de9c C |
66 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
67 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | |
68 | const data = await createActivityData(url, byActor, dislikeActivity, t, audience) | |
0032ebe9 | 69 | |
50d6de9c | 70 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
0032ebe9 | 71 | } |
40ff5707 | 72 | |
50d6de9c C |
73 | async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
74 | const url = getVideoDislikeActivityPubUrl(byActor, video) | |
75 | const dislikeActivity = createDislikeActivityData(byActor, video) | |
0032ebe9 | 76 | |
50d6de9c C |
77 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
78 | const audience = getObjectFollowersAudience(actorsToForwardView) | |
79 | const data = await createActivityData(url, byActor, dislikeActivity, t, audience) | |
0032ebe9 | 80 | |
50d6de9c C |
81 | const followersException = [ byActor ] |
82 | return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) | |
40ff5707 C |
83 | } |
84 | ||
3fd3ab2d C |
85 | async function createActivityData ( |
86 | url: string, | |
50d6de9c | 87 | byActor: ActorModel, |
3fd3ab2d C |
88 | object: any, |
89 | t: Transaction, | |
90 | audience?: ActivityAudience | |
91 | ): Promise<ActivityCreate> { | |
40ff5707 | 92 | if (!audience) { |
50d6de9c | 93 | audience = await getAudience(byActor, t) |
40ff5707 | 94 | } |
c986175d | 95 | |
3fd3ab2d | 96 | return { |
54141398 C |
97 | type: 'Create', |
98 | id: url, | |
50d6de9c | 99 | actor: byActor.url, |
40ff5707 C |
100 | to: audience.to, |
101 | cc: audience.cc, | |
54141398 C |
102 | object |
103 | } | |
54141398 C |
104 | } |
105 | ||
50d6de9c | 106 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { |
3fd3ab2d | 107 | return { |
0032ebe9 | 108 | type: 'Dislike', |
50d6de9c | 109 | actor: byActor.url, |
0032ebe9 C |
110 | object: video.url |
111 | } | |
0032ebe9 C |
112 | } |
113 | ||
54141398 C |
114 | // --------------------------------------------------------------------------- |
115 | ||
116 | export { | |
50d6de9c | 117 | sendCreateVideo, |
54141398 | 118 | sendVideoAbuse, |
40ff5707 C |
119 | createActivityData, |
120 | sendCreateViewToOrigin, | |
0032ebe9 C |
121 | sendCreateViewToVideoFollowers, |
122 | sendCreateDislikeToOrigin, | |
123 | sendCreateDislikeToVideoFollowers, | |
124 | createDislikeActivityData | |
40ff5707 C |
125 | } |
126 | ||
127 | // --------------------------------------------------------------------------- | |
128 | ||
50d6de9c | 129 | function createViewActivityData (byActor: ActorModel, video: VideoModel) { |
3fd3ab2d | 130 | return { |
40ff5707 | 131 | type: 'View', |
50d6de9c | 132 | actor: byActor.url, |
40ff5707 C |
133 | object: video.url |
134 | } | |
54141398 | 135 | } |