aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/video-rates.ts
blob: 19011b4ab835efb47a10515dcdc2d5ad4887846d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Transaction } from 'sequelize'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'

async function sendVideoRateChange (account: AccountModel,
                              video: VideoModel,
                              likes: number,
                              dislikes: number,
                              t: Transaction) {
  const actor = account.Actor

  // Keep the order: first we undo and then we create

  // Undo Like
  if (likes < 0) await sendUndoLike(actor, video, t)
  // Undo Dislike
  if (dislikes < 0) await sendUndoDislike(actor, video, t)

  // Like
  if (likes > 0) await sendLike(actor, video, t)
  // Dislike
  if (dislikes > 0) await sendCreateDislike(actor, video, t)
}

export {
  sendVideoRateChange
}