]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
3fd3ab2d | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
50d6de9c | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
da854ddd | 4 | import { getServerActor } from '../../../helpers/utils' |
50d6de9c | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
3fd3ab2d C |
6 | import { VideoModel } from '../../../models/video/video' |
7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | |
ea44f375 | 8 | import { VideoCommentModel } from '../../../models/video/video-comment' |
0032ebe9 C |
9 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
10 | import { | |
d7e70384 C |
11 | audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, |
12 | getOriginVideoAudience, getOriginVideoCommentAudience, | |
0032ebe9 C |
13 | unicastTo |
14 | } from './misc' | |
54141398 | 15 | |
50d6de9c | 16 | async function sendCreateVideo (video: VideoModel, t: Transaction) { |
54b38063 | 17 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined |
54141398 | 18 | |
e12a0092 | 19 | const byActor = video.VideoChannel.Account.Actor |
50d6de9c | 20 | const videoObject = video.toActivityPubObject() |
e12a0092 | 21 | |
50d6de9c C |
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 | ||
ea44f375 C |
37 | async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { |
38 | const byActor = comment.Account.Actor | |
d7e70384 C |
39 | const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) |
40 | const commentObject = comment.toActivityPubObject(threadParentComments) | |
ea44f375 C |
41 | |
42 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) | |
d7e70384 | 43 | const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) |
ea44f375 | 44 | |
ea44f375 C |
45 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) |
46 | ||
47 | return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t) | |
48 | } | |
49 | ||
50 | async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { | |
51 | const byActor = comment.Account.Actor | |
d7e70384 C |
52 | const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) |
53 | const commentObject = comment.toActivityPubObject(threadParentComments) | |
ea44f375 | 54 | |
d7e70384 C |
55 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) |
56 | const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) | |
ea44f375 C |
57 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) |
58 | ||
59 | const followersException = [ byActor ] | |
d7e70384 | 60 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
ea44f375 C |
61 | } |
62 | ||
50d6de9c C |
63 | async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
64 | const url = getVideoViewActivityPubUrl(byActor, video) | |
ea44f375 | 65 | const viewActivityData = createViewActivityData(byActor, video) |
40ff5707 | 66 | |
50d6de9c C |
67 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
68 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | |
ea44f375 | 69 | const data = await createActivityData(url, byActor, viewActivityData, t, audience) |
54141398 | 70 | |
50d6de9c | 71 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
54141398 C |
72 | } |
73 | ||
50d6de9c C |
74 | async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
75 | const url = getVideoViewActivityPubUrl(byActor, video) | |
ea44f375 | 76 | const viewActivityData = createViewActivityData(byActor, video) |
40ff5707 | 77 | |
50d6de9c C |
78 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
79 | const audience = getObjectFollowersAudience(actorsToForwardView) | |
ea44f375 | 80 | const data = await createActivityData(url, byActor, viewActivityData, t, audience) |
40ff5707 | 81 | |
50d6de9c C |
82 | // Use the server actor to send the view |
83 | const serverActor = await getServerActor() | |
84 | const followersException = [ byActor ] | |
85 | return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) | |
0032ebe9 C |
86 | } |
87 | ||
50d6de9c C |
88 | async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { |
89 | const url = getVideoDislikeActivityPubUrl(byActor, video) | |
ea44f375 | 90 | const dislikeActivityData = createDislikeActivityData(byActor, video) |
0032ebe9 | 91 | |
50d6de9c C |
92 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
93 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | |
ea44f375 | 94 | const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) |
0032ebe9 | 95 | |
50d6de9c | 96 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) |
0032ebe9 | 97 | } |
40ff5707 | 98 | |
50d6de9c C |
99 | async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { |
100 | const url = getVideoDislikeActivityPubUrl(byActor, video) | |
ea44f375 | 101 | const dislikeActivityData = createDislikeActivityData(byActor, video) |
0032ebe9 | 102 | |
50d6de9c C |
103 | const actorsToForwardView = await getActorsInvolvedInVideo(video, t) |
104 | const audience = getObjectFollowersAudience(actorsToForwardView) | |
ea44f375 | 105 | const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) |
0032ebe9 | 106 | |
50d6de9c C |
107 | const followersException = [ byActor ] |
108 | return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) | |
40ff5707 C |
109 | } |
110 | ||
3fd3ab2d C |
111 | async function createActivityData ( |
112 | url: string, | |
50d6de9c | 113 | byActor: ActorModel, |
3fd3ab2d C |
114 | object: any, |
115 | t: Transaction, | |
116 | audience?: ActivityAudience | |
117 | ): Promise<ActivityCreate> { | |
40ff5707 | 118 | if (!audience) { |
50d6de9c | 119 | audience = await getAudience(byActor, t) |
40ff5707 | 120 | } |
c986175d | 121 | |
e12a0092 | 122 | return audiencify({ |
54141398 C |
123 | type: 'Create', |
124 | id: url, | |
50d6de9c | 125 | actor: byActor.url, |
e12a0092 C |
126 | object: audiencify(object, audience) |
127 | }, audience) | |
54141398 C |
128 | } |
129 | ||
50d6de9c | 130 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { |
3fd3ab2d | 131 | return { |
0032ebe9 | 132 | type: 'Dislike', |
50d6de9c | 133 | actor: byActor.url, |
0032ebe9 C |
134 | object: video.url |
135 | } | |
0032ebe9 C |
136 | } |
137 | ||
ea44f375 C |
138 | function createViewActivityData (byActor: ActorModel, video: VideoModel) { |
139 | return { | |
140 | type: 'View', | |
141 | actor: byActor.url, | |
142 | object: video.url | |
143 | } | |
144 | } | |
145 | ||
54141398 C |
146 | // --------------------------------------------------------------------------- |
147 | ||
148 | export { | |
50d6de9c | 149 | sendCreateVideo, |
54141398 | 150 | sendVideoAbuse, |
40ff5707 C |
151 | createActivityData, |
152 | sendCreateViewToOrigin, | |
0032ebe9 C |
153 | sendCreateViewToVideoFollowers, |
154 | sendCreateDislikeToOrigin, | |
155 | sendCreateDislikeToVideoFollowers, | |
ea44f375 C |
156 | createDislikeActivityData, |
157 | sendCreateVideoCommentToOrigin, | |
158 | sendCreateVideoCommentToVideoFollowers | |
54141398 | 159 | } |