diff options
Diffstat (limited to 'server/lib/activitypub/video-rates.ts')
-rw-r--r-- | server/lib/activitypub/video-rates.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts new file mode 100644 index 000000000..1b2958cca --- /dev/null +++ b/server/lib/activitypub/video-rates.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { AccountModel } from '../../models/account/account' | ||
3 | import { VideoModel } from '../../models/video/video' | ||
4 | import { | ||
5 | sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, sendLikeToOrigin, sendLikeToVideoFollowers, sendUndoDislikeToOrigin, | ||
6 | sendUndoDislikeToVideoFollowers, sendUndoLikeToOrigin, sendUndoLikeToVideoFollowers | ||
7 | } from './send' | ||
8 | |||
9 | async function sendVideoRateChangeToFollowers (account: AccountModel, | ||
10 | video: VideoModel, | ||
11 | likes: number, | ||
12 | dislikes: number, | ||
13 | t: Transaction) { | ||
14 | const actor = account.Actor | ||
15 | |||
16 | // Keep the order: first we undo and then we create | ||
17 | |||
18 | // Undo Like | ||
19 | if (likes < 0) await sendUndoLikeToVideoFollowers(actor, video, t) | ||
20 | // Undo Dislike | ||
21 | if (dislikes < 0) await sendUndoDislikeToVideoFollowers(actor, video, t) | ||
22 | |||
23 | // Like | ||
24 | if (likes > 0) await sendLikeToVideoFollowers(actor, video, t) | ||
25 | // Dislike | ||
26 | if (dislikes > 0) await sendCreateDislikeToVideoFollowers(actor, video, t) | ||
27 | } | ||
28 | |||
29 | async 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 | } | ||
48 | |||
49 | export { | ||
50 | sendVideoRateChangeToFollowers, | ||
51 | sendVideoRateChangeToOrigin | ||
52 | } | ||