]>
Commit | Line | Data |
---|---|---|
2ccaeeb3 C |
1 | import { Transaction } from 'sequelize' |
2 | import { AccountModel } from '../../models/account/account' | |
3 | import { VideoModel } from '../../models/video/video' | |
07197db4 | 4 | import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send' |
2ccaeeb3 | 5 | |
07197db4 C |
6 | async 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 | ||
26 | export { | |
07197db4 | 27 | sendVideoRateChange |
2ccaeeb3 | 28 | } |