1 import { Transaction } from 'sequelize'
2 import { VideoRateType } from '../../../shared/models/videos'
3 import { MAccountActor, MActorUrl, MVideoAccountLight, MVideoFullLight, MVideoId } from '../../types/models'
4 import { sendLike, sendUndoDislike, sendUndoLike } from './send'
5 import { sendDislike } from './send/send-dislike'
6 import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url'
7 import { federateVideoIfNeeded } from './videos'
9 async function sendVideoRateChange (
10 account: MAccountActor,
11 video: MVideoFullLight,
16 if (video.isOwned()) return federateVideoIfNeeded(video, false, t)
18 return sendVideoRateChangeToOrigin(account, video, likes, dislikes, t)
21 function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) {
22 return rateType === 'like'
23 ? getVideoLikeActivityPubUrlByLocalActor(actor, video)
24 : getVideoDislikeActivityPubUrlByLocalActor(actor, video)
27 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 async function sendVideoRateChangeToOrigin (
37 account: MAccountActor,
38 video: MVideoAccountLight,
43 // Local video, we don't need to send like
44 if (video.isOwned()) return
46 const actor = account.Actor
48 // Keep the order: first we undo and then we create
51 if (likes < 0) await sendUndoLike(actor, video, t)
53 if (dislikes < 0) await sendUndoDislike(actor, video, t)
56 if (likes > 0) await sendLike(actor, video, t)
58 if (dislikes > 0) await sendDislike(actor, video, t)