aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/client.ts4
-rw-r--r--server/controllers/api/videos/index.ts8
-rw-r--r--server/controllers/api/videos/rate.ts8
-rw-r--r--server/lib/activitypub/index.ts7
-rw-r--r--server/lib/activitypub/send/send-announce.ts10
-rw-r--r--server/lib/activitypub/send/send-create.ts102
-rw-r--r--server/lib/activitypub/send/send-like.ts19
-rw-r--r--server/lib/activitypub/send/send-undo.ts49
-rw-r--r--server/lib/activitypub/share.ts6
-rw-r--r--server/lib/activitypub/video-rates.ts46
-rw-r--r--server/lib/video-comment.ts8
11 files changed, 99 insertions, 168 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 347079816..8e295b4f9 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -4,7 +4,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' 4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
5import { pageToStartAndCount } from '../../helpers/core-utils' 5import { pageToStartAndCount } from '../../helpers/core-utils'
6import { ACTIVITY_PUB, CONFIG } from '../../initializers' 6import { ACTIVITY_PUB, CONFIG } from '../../initializers'
7import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' 7import { buildVideoAnnounce } from '../../lib/activitypub/send'
8import { audiencify, getAudience } from '../../lib/activitypub/send/misc' 8import { audiencify, getAudience } from '../../lib/activitypub/send/misc'
9import { createActivityData } from '../../lib/activitypub/send/send-create' 9import { createActivityData } from '../../lib/activitypub/send/send-create'
10import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' 10import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
@@ -130,7 +130,7 @@ async function videoController (req: express.Request, res: express.Response, nex
130 130
131async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 131async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
132 const share = res.locals.videoShare as VideoShareModel 132 const share = res.locals.videoShare as VideoShareModel
133 const object = await buildVideoAnnounceToFollowers(share.Actor, share, res.locals.video, undefined) 133 const object = await buildVideoAnnounce(share.Actor, share, res.locals.video, undefined)
134 134
135 return res.json(activityPubContextify(object)) 135 return res.json(activityPubContextify(object))
136} 136}
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 690872320..552e5edac 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -20,7 +20,7 @@ import {
20 VIDEO_PRIVACIES 20 VIDEO_PRIVACIES
21} from '../../../initializers' 21} from '../../../initializers'
22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
23import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' 23import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
24import { JobQueue } from '../../../lib/job-queue' 24import { JobQueue } from '../../../lib/job-queue'
25import { Redis } from '../../../lib/redis' 25import { Redis } from '../../../lib/redis'
26import { 26import {
@@ -365,11 +365,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
365 365
366 const serverAccount = await getServerActor() 366 const serverAccount = await getServerActor()
367 367
368 if (videoInstance.isOwned()) { 368 await sendCreateView(serverAccount, videoInstance, undefined)
369 await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
370 } else {
371 await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
372 }
373 369
374 return res.status(204).end() 370 return res.status(204).end()
375} 371}
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index a7bd570eb..23e9de9f3 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -3,7 +3,7 @@ import { UserVideoRateUpdate } from '../../../../shared'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' 5import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers'
6import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' 6import { sendVideoRateChange } from '../../../lib/activitypub'
7import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' 7import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares'
8import { AccountModel } from '../../../models/account/account' 8import { AccountModel } from '../../../models/account/account'
9import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 9import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
@@ -83,11 +83,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
83 // It is useful for the user to have a feedback 83 // It is useful for the user to have a feedback
84 await videoInstance.increment(incrementQuery, sequelizeOptions) 84 await videoInstance.increment(incrementQuery, sequelizeOptions)
85 85
86 if (videoInstance.isOwned()) { 86 await sendVideoRateChange(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
87 await sendVideoRateChangeToFollowers(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
88 } else {
89 await sendVideoRateChangeToOrigin(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
90 }
91 }) 87 })
92 88
93 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) 89 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts
index 0779d1e91..88064c6b6 100644
--- a/server/lib/activitypub/index.ts
+++ b/server/lib/activitypub/index.ts
@@ -4,9 +4,6 @@ export * from './actor'
4export * from './fetch' 4export * from './fetch'
5export * from './share' 5export * from './share'
6export * from './videos' 6export * from './videos'
7export * from './video-comments'
8export * from './video-rates'
7export * from './url' 9export * from './url'
8export { videoCommentActivityObjectToDBAttributes } from './video-comments'
9export { addVideoComments } from './video-comments'
10export { addVideoComment } from './video-comments'
11export { sendVideoRateChangeToFollowers } from './video-rates'
12export { sendVideoRateChangeToOrigin } from './video-rates'
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts
index ed551a2b2..4179c9d43 100644
--- a/server/lib/activitypub/send/send-announce.ts
+++ b/server/lib/activitypub/send/send-announce.ts
@@ -5,7 +5,7 @@ import { VideoModel } from '../../../models/video/video'
5import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
6import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc' 6import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc'
7 7
8async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { 8async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
9 const announcedObject = video.url 9 const announcedObject = video.url
10 10
11 const accountsToForwardView = await getActorsInvolvedInVideo(video, t) 11 const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
@@ -13,8 +13,8 @@ async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: V
13 return announceActivityData(videoShare.url, byActor, announcedObject, t, audience) 13 return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
14} 14}
15 15
16async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { 16async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
17 const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t) 17 const data = await buildVideoAnnounce(byActor, videoShare, video, t)
18 18
19 return broadcastToFollowers(data, byActor, [ byActor ], t) 19 return broadcastToFollowers(data, byActor, [ byActor ], t)
20} 20}
@@ -43,7 +43,7 @@ async function announceActivityData (
43// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
44 44
45export { 45export {
46 sendVideoAnnounceToFollowers, 46 sendVideoAnnounce,
47 announceActivityData, 47 announceActivityData,
48 buildVideoAnnounceToFollowers 48 buildVideoAnnounce
49} 49}
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index d73dd8d24..4ff20b033 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -40,105 +40,92 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
40 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 40 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
41} 41}
42 42
43async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { 43async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
44 const isOrigin = comment.Video.isOwned()
45
44 const byActor = comment.Account.Actor 46 const byActor = comment.Account.Actor
45 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 47 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
46 const commentObject = comment.toActivityPubObject(threadParentComments) 48 const commentObject = comment.toActivityPubObject(threadParentComments)
47 49
48 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t) 50 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
49 actorsInvolvedInComment.push(byActor) 51 actorsInvolvedInComment.push(byActor)
50 const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
51
52 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
53
54 // This was a reply, send it to the parent actors
55 const actorsException = [ byActor ]
56 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
57
58 // Broadcast to our followers
59 await broadcastToFollowers(data, byActor, [ byActor ], t)
60 52
61 // Send to origin 53 const parentsCommentActors = threadParentComments.map(c => c.Account.Actor)
62 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
63}
64 54
65async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { 55 let audience: ActivityAudience
66 const byActor = comment.Account.Actor 56 if (isOrigin) {
67 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 57 audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
68 const commentObject = comment.toActivityPubObject(threadParentComments) 58 } else {
69 59 audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
70 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t) 60 }
71 actorsInvolvedInComment.push(byActor)
72 61
73 const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, true)
74 const data = await createActivityData(comment.url, byActor, commentObject, t, audience) 62 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
75 63
76 // This was a reply, send it to the parent actors 64 // This was a reply, send it to the parent actors
77 const actorsException = [ byActor ] 65 const actorsException = [ byActor ]
78 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException) 66 await broadcastToActors(data, byActor, parentsCommentActors, actorsException)
79 67
80 // Broadcast to our followers 68 // Broadcast to our followers
81 await broadcastToFollowers(data, byActor, [ byActor ], t) 69 await broadcastToFollowers(data, byActor, [ byActor ], t)
82 70
83 // Send to actors involved in the comment 71 // Send to actors involved in the comment
84 return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException) 72 if (isOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
73
74 // Send to origin
75 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
85} 76}
86 77
87async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 78async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
88 const url = getVideoViewActivityPubUrl(byActor, video) 79 const url = getVideoViewActivityPubUrl(byActor, video)
89 const viewActivityData = createViewActivityData(byActor, video) 80 const viewActivityData = createViewActivityData(byActor, video)
90 81
91 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 82 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
92 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
93 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
94 83
95 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 84 // Send to origin
96} 85 if (video.isOwned() === false) {
86 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
87 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
97 88
98async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 89 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
99 const url = getVideoViewActivityPubUrl(byActor, video) 90 }
100 const viewActivityData = createViewActivityData(byActor, video)
101 91
102 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 92 // Send to followers
103 const audience = getObjectFollowersAudience(actorsToForwardView) 93 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
104 const data = await createActivityData(url, byActor, viewActivityData, t, audience) 94 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
105 95
106 // Use the server actor to send the view 96 // Use the server actor to send the view
107 const serverActor = await getServerActor() 97 const serverActor = await getServerActor()
108 const actorsException = [ byActor ] 98 const actorsException = [ byActor ]
109 return broadcastToFollowers(data, serverActor, actorsToForwardView, t, actorsException) 99 return broadcastToFollowers(data, serverActor, actorsInvolvedInVideo, t, actorsException)
110} 100}
111 101
112async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 102async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
113 const url = getVideoDislikeActivityPubUrl(byActor, video) 103 const url = getVideoDislikeActivityPubUrl(byActor, video)
114 const dislikeActivityData = createDislikeActivityData(byActor, video) 104 const dislikeActivityData = createDislikeActivityData(byActor, video)
115 105
116 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 106 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
117 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
118 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
119 107
120 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 108 // Send to origin
121} 109 if (video.isOwned() === false) {
110 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
111 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
122 112
123async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 113 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
124 const url = getVideoDislikeActivityPubUrl(byActor, video) 114 }
125 const dislikeActivityData = createDislikeActivityData(byActor, video)
126 115
127 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 116 // Send to followers
128 const audience = getObjectFollowersAudience(actorsToForwardView) 117 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
129 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) 118 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
130 119
131 const actorsException = [ byActor ] 120 const actorsException = [ byActor ]
132 return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException) 121 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException)
133} 122}
134 123
135async function createActivityData ( 124async function createActivityData (url: string,
136 url: string, 125 byActor: ActorModel,
137 byActor: ActorModel, 126 object: any,
138 object: any, 127 t: Transaction,
139 t: Transaction, 128 audience?: ActivityAudience): Promise<ActivityCreate> {
140 audience?: ActivityAudience
141): Promise<ActivityCreate> {
142 if (!audience) { 129 if (!audience) {
143 audience = await getAudience(byActor, t) 130 audience = await getAudience(byActor, t)
144 } 131 }
@@ -173,11 +160,8 @@ export {
173 sendCreateVideo, 160 sendCreateVideo,
174 sendVideoAbuse, 161 sendVideoAbuse,
175 createActivityData, 162 createActivityData,
176 sendCreateViewToOrigin, 163 sendCreateView,
177 sendCreateViewToVideoFollowers, 164 sendCreateDislike,
178 sendCreateDislikeToOrigin,
179 sendCreateDislikeToVideoFollowers,
180 createDislikeActivityData, 165 createDislikeActivityData,
181 sendCreateVideoCommentToOrigin, 166 sendCreateVideoComment
182 sendCreateVideoCommentToVideoFollowers
183} 167}
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index b01249e69..fb2b4aaf8 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -13,20 +13,20 @@ import {
13 unicastTo 13 unicastTo
14} from './misc' 14} from './misc'
15 15
16async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 16async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
17 const url = getVideoLikeActivityPubUrl(byActor, video) 17 const url = getVideoLikeActivityPubUrl(byActor, video)
18 18
19 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 19 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
20 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
21 const data = await likeActivityData(url, byActor, video, t, audience)
22 20
23 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 21 // Send to origin
24} 22 if (video.isOwned() === false) {
23 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
24 const data = await likeActivityData(url, byActor, video, t, audience)
25 25
26async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 26 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
27 const url = getVideoLikeActivityPubUrl(byActor, video) 27 }
28 28
29 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 29 // Send to followers
30 const audience = getObjectFollowersAudience(accountsInvolvedInVideo) 30 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
31 const data = await likeActivityData(url, byActor, video, t, audience) 31 const data = await likeActivityData(url, byActor, video, t, audience)
32 32
@@ -56,7 +56,6 @@ async function likeActivityData (
56// --------------------------------------------------------------------------- 56// ---------------------------------------------------------------------------
57 57
58export { 58export {
59 sendLikeToOrigin, 59 sendLike,
60 sendLikeToVideoFollowers,
61 likeActivityData 60 likeActivityData
62} 61}
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index 41a500384..bd49d452e 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -30,68 +30,55 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
30 return unicastTo(data, me, following.inboxUrl) 30 return unicastTo(data, me, following.inboxUrl)
31} 31}
32 32
33async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 33async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
34 const likeUrl = getVideoLikeActivityPubUrl(byActor, video) 34 const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
35 const undoUrl = getUndoActivityPubUrl(likeUrl) 35 const undoUrl = getUndoActivityPubUrl(likeUrl)
36 36
37 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 37 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
38 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
39 const object = await likeActivityData(likeUrl, byActor, video, t) 38 const object = await likeActivityData(likeUrl, byActor, video, t)
40 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
41 39
42 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 40 // Send to origin
43} 41 if (video.isOwned() === false) {
42 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
43 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
44 44
45async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 45 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
46 const likeUrl = getVideoLikeActivityPubUrl(byActor, video) 46 }
47 const undoUrl = getUndoActivityPubUrl(likeUrl)
48 47
49 const toActorsFollowers = await getActorsInvolvedInVideo(video, t) 48 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
50 const audience = getObjectFollowersAudience(toActorsFollowers)
51 const object = await likeActivityData(likeUrl, byActor, video, t)
52 const data = await undoActivityData(undoUrl, byActor, object, t, audience) 49 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
53 50
54 const followersException = [ byActor ] 51 const followersException = [ byActor ]
55 return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) 52 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
56} 53}
57 54
58async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 55async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
59 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) 56 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
60 const undoUrl = getUndoActivityPubUrl(dislikeUrl) 57 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
61 58
62 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 59 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
63 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
64 const dislikeActivity = createDislikeActivityData(byActor, video) 60 const dislikeActivity = createDislikeActivityData(byActor, video)
65 const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) 61 const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
66 62
67 const data = await undoActivityData(undoUrl, byActor, object, t, audience) 63 if (video.isOwned() === false) {
68 64 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
69 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 65 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
70}
71
72async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
73 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
74 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
75 66
76 const dislikeActivity = createDislikeActivityData(byActor, video) 67 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
77 const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) 68 }
78 69
79 const data = await undoActivityData(undoUrl, byActor, object, t) 70 const data = await undoActivityData(undoUrl, byActor, object, t)
80 71
81 const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
82
83 const followersException = [ byActor ] 72 const followersException = [ byActor ]
84 return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) 73 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
85} 74}
86 75
87// --------------------------------------------------------------------------- 76// ---------------------------------------------------------------------------
88 77
89export { 78export {
90 sendUndoFollow, 79 sendUndoFollow,
91 sendUndoLikeToOrigin, 80 sendUndoLike,
92 sendUndoLikeToVideoFollowers, 81 sendUndoDislike
93 sendUndoDislikeToOrigin,
94 sendUndoDislikeToVideoFollowers
95} 82}
96 83
97// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index 038f19b7d..f256f8d21 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -3,7 +3,7 @@ import { VideoPrivacy } from '../../../shared/models/videos'
3import { getServerActor } from '../../helpers/utils' 3import { getServerActor } from '../../helpers/utils'
4import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
5import { VideoShareModel } from '../../models/video/video-share' 5import { VideoShareModel } from '../../models/video/video-share'
6import { sendVideoAnnounceToFollowers } from './send' 6import { sendVideoAnnounce } from './send'
7import { getAnnounceActivityPubUrl } from './url' 7import { getAnnounceActivityPubUrl } from './url'
8 8
9async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { 9async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
@@ -23,7 +23,7 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction)
23 }, 23 },
24 transaction: t 24 transaction: t
25 }).then(([ serverShare, created ]) => { 25 }).then(([ serverShare, created ]) => {
26 if (created) return sendVideoAnnounceToFollowers(serverActor, serverShare, video, t) 26 if (created) return sendVideoAnnounce(serverActor, serverShare, video, t)
27 27
28 return undefined 28 return undefined
29 }) 29 })
@@ -40,7 +40,7 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction)
40 }, 40 },
41 transaction: t 41 transaction: t
42 }).then(([ videoChannelShare, created ]) => { 42 }).then(([ videoChannelShare, created ]) => {
43 if (created) return sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t) 43 if (created) return sendVideoAnnounce(serverActor, videoChannelShare, video, t)
44 44
45 return undefined 45 return undefined
46 }) 46 })
diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts
index 1b2958cca..19011b4ab 100644
--- a/server/lib/activitypub/video-rates.ts
+++ b/server/lib/activitypub/video-rates.ts
@@ -1,52 +1,28 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { AccountModel } from '../../models/account/account' 2import { AccountModel } from '../../models/account/account'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { 4import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
5 sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, sendLikeToOrigin, sendLikeToVideoFollowers, sendUndoDislikeToOrigin,
6 sendUndoDislikeToVideoFollowers, sendUndoLikeToOrigin, sendUndoLikeToVideoFollowers
7} from './send'
8 5
9async function sendVideoRateChangeToFollowers (account: AccountModel, 6async function sendVideoRateChange (account: AccountModel,
10 video: VideoModel, 7 video: VideoModel,
11 likes: number, 8 likes: number,
12 dislikes: number, 9 dislikes: number,
13 t: Transaction) { 10 t: Transaction) {
14 const actor = account.Actor 11 const actor = account.Actor
15 12
16 // Keep the order: first we undo and then we create 13 // Keep the order: first we undo and then we create
17 14
18 // Undo Like 15 // Undo Like
19 if (likes < 0) await sendUndoLikeToVideoFollowers(actor, video, t) 16 if (likes < 0) await sendUndoLike(actor, video, t)
20 // Undo Dislike 17 // Undo Dislike
21 if (dislikes < 0) await sendUndoDislikeToVideoFollowers(actor, video, t) 18 if (dislikes < 0) await sendUndoDislike(actor, video, t)
22 19
23 // Like 20 // Like
24 if (likes > 0) await sendLikeToVideoFollowers(actor, video, t) 21 if (likes > 0) await sendLike(actor, video, t)
25 // Dislike 22 // Dislike
26 if (dislikes > 0) await sendCreateDislikeToVideoFollowers(actor, video, t) 23 if (dislikes > 0) await sendCreateDislike(actor, video, t)
27}
28
29async function sendVideoRateChangeToOrigin (account: AccountModel,
30 video: VideoModel,
31 likes: number,
32 dislikes: number,
33 t: Transaction) {
34 const actor = account.Actor
35
36 // Keep the order: first we undo and then we create
37
38 // Undo Like
39 if (likes < 0) await sendUndoLikeToOrigin(actor, video, t)
40 // Undo Dislike
41 if (dislikes < 0) await sendUndoDislikeToOrigin(actor, video, t)
42
43 // Like
44 if (likes > 0) await sendLikeToOrigin(actor, video, t)
45 // Dislike
46 if (dislikes > 0) await sendCreateDislikeToOrigin(actor, video, t)
47} 24}
48 25
49export { 26export {
50 sendVideoRateChangeToFollowers, 27 sendVideoRateChange
51 sendVideoRateChangeToOrigin
52} 28}
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index 0d744c526..f88e5cfdf 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -5,7 +5,7 @@ import { AccountModel } from '../models/account/account'
5import { VideoModel } from '../models/video/video' 5import { VideoModel } from '../models/video/video'
6import { VideoCommentModel } from '../models/video/video-comment' 6import { VideoCommentModel } from '../models/video/video-comment'
7import { getVideoCommentActivityPubUrl } from './activitypub' 7import { getVideoCommentActivityPubUrl } from './activitypub'
8import { sendCreateVideoCommentToOrigin, sendCreateVideoCommentToVideoFollowers } from './activitypub/send' 8import { sendCreateVideoComment } from './activitypub/send'
9 9
10async function createVideoComment (obj: { 10async function createVideoComment (obj: {
11 text: string, 11 text: string,
@@ -37,11 +37,7 @@ async function createVideoComment (obj: {
37 savedComment.Video = obj.video 37 savedComment.Video = obj.video
38 savedComment.Account = obj.account 38 savedComment.Account = obj.account
39 39
40 if (savedComment.Video.isOwned()) { 40 await sendCreateVideoComment(savedComment, t)
41 await sendCreateVideoCommentToVideoFollowers(savedComment, t)
42 } else {
43 await sendCreateVideoCommentToOrigin(savedComment, t)
44 }
45 41
46 return savedComment 42 return savedComment
47} 43}