]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/video-rates.ts
Refresh orphan actors
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / video-rates.ts
CommitLineData
2ccaeeb3
C
1import { Transaction } from 'sequelize'
2import { AccountModel } from '../../models/account/account'
3import { VideoModel } from '../../models/video/video'
07197db4 4import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
2ccaeeb3 5
07197db4
C
6async function sendVideoRateChange (account: AccountModel,
7 video: VideoModel,
8 likes: number,
9 dislikes: number,
10 t: Transaction) {
2ccaeeb3
C
11 const actor = account.Actor
12
13 // Keep the order: first we undo and then we create
14
15 // Undo Like
07197db4 16 if (likes < 0) await sendUndoLike(actor, video, t)
2ccaeeb3 17 // Undo Dislike
07197db4 18 if (dislikes < 0) await sendUndoDislike(actor, video, t)
2ccaeeb3
C
19
20 // Like
07197db4 21 if (likes > 0) await sendLike(actor, video, t)
2ccaeeb3 22 // Dislike
07197db4 23 if (dislikes > 0) await sendCreateDislike(actor, video, t)
2ccaeeb3
C
24}
25
26export {
07197db4 27 sendVideoRateChange
2ccaeeb3 28}