aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/video-rates.ts
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/video-rates.ts
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/video-rates.ts')
-rw-r--r--server/lib/activitypub/video-rates.ts46
1 files changed, 11 insertions, 35 deletions
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}