1
0
Fork 0
peertube/server/lib/activitypub/video-rates.ts

29 lines
889 B
TypeScript
Raw Normal View History

2018-01-10 11:18:12 -05:00
import { Transaction } from 'sequelize'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
2018-01-10 11:18:12 -05:00
async function sendVideoRateChange (account: AccountModel,
video: VideoModel,
likes: number,
dislikes: number,
t: Transaction) {
2018-01-10 11:18:12 -05:00
const actor = account.Actor
// Keep the order: first we undo and then we create
// Undo Like
if (likes < 0) await sendUndoLike(actor, video, t)
2018-01-10 11:18:12 -05:00
// Undo Dislike
if (dislikes < 0) await sendUndoDislike(actor, video, t)
2018-01-10 11:18:12 -05:00
// Like
if (likes > 0) await sendLike(actor, video, t)
2018-01-10 11:18:12 -05:00
// Dislike
if (dislikes > 0) await sendCreateDislike(actor, video, t)
2018-01-10 11:18:12 -05:00
}
export {
sendVideoRateChange
2018-01-10 11:18:12 -05:00
}