]>
Commit | Line | Data |
---|---|---|
1 | import { Transaction } from 'sequelize' | |
2 | import { AccountModel } from '../../models/account/account' | |
3 | import { VideoModel } from '../../models/video/video' | |
4 | import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send' | |
5 | ||
6 | async function sendVideoRateChange (account: AccountModel, | |
7 | video: VideoModel, | |
8 | likes: number, | |
9 | dislikes: number, | |
10 | t: Transaction) { | |
11 | const actor = account.Actor | |
12 | ||
13 | // Keep the order: first we undo and then we create | |
14 | ||
15 | // Undo Like | |
16 | if (likes < 0) await sendUndoLike(actor, video, t) | |
17 | // Undo Dislike | |
18 | if (dislikes < 0) await sendUndoDislike(actor, video, t) | |
19 | ||
20 | // Like | |
21 | if (likes > 0) await sendLike(actor, video, t) | |
22 | // Dislike | |
23 | if (dislikes > 0) await sendCreateDislike(actor, video, t) | |
24 | } | |
25 | ||
26 | export { | |
27 | sendVideoRateChange | |
28 | } |