aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-03-27 13:33:56 +0200
committerChocobozzz <me@florianbigard.com>2018-03-27 13:33:56 +0200
commit07197db4c567f22bbc9c12339062896dc76bac2f (patch)
tree5682f0d88fc1b4032018e5122ed42eb9967fd743 /server/lib/activitypub
parentda99ccf2681bcbc172a96cf30e7b733948767faa (diff)
downloadPeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.tar.gz
PeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.tar.zst
PeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.zip
Try to refractor activities sending
There is still a need for work on this part though
Diffstat (limited to 'server/lib/activitypub')
-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
7 files changed, 91 insertions, 148 deletions
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}