X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fvideo-rates.ts;h=2e7920f4e2d0d8dc83ea1fdb3800a45c22d0cf17;hb=c5cadb2859050449596199090231d6e38bc4a571;hp=19011b4ab835efb47a10515dcdc2d5ad4887846d;hpb=07197db4c567f22bbc9c12339062896dc76bac2f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts index 19011b4ab..2e7920f4e 100644 --- a/server/lib/activitypub/video-rates.ts +++ b/server/lib/activitypub/video-rates.ts @@ -1,13 +1,48 @@ 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) { +import { VideoRateType } from '../../../shared/models/videos' +import { MAccountActor, MActorUrl, MVideoAccountLight, MVideoFullLight, MVideoId } from '../../types/models' +import { sendLike, sendUndoDislike, sendUndoLike } from './send' +import { sendDislike } from './send/send-dislike' +import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url' +import { federateVideoIfNeeded } from './videos' + +async function sendVideoRateChange ( + account: MAccountActor, + video: MVideoFullLight, + likes: number, + dislikes: number, + t: Transaction +) { + if (video.isOwned()) return federateVideoIfNeeded(video, false, t) + + return sendVideoRateChangeToOrigin(account, video, likes, dislikes, t) +} + +function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { + return rateType === 'like' + ? getVideoLikeActivityPubUrlByLocalActor(actor, video) + : getVideoDislikeActivityPubUrlByLocalActor(actor, video) +} + +// --------------------------------------------------------------------------- + +export { + getLocalRateUrl, + sendVideoRateChange +} + +// --------------------------------------------------------------------------- + +async function sendVideoRateChangeToOrigin ( + account: MAccountActor, + video: MVideoAccountLight, + likes: number, + dislikes: number, + t: Transaction +) { + // Local video, we don't need to send like + if (video.isOwned()) return + const actor = account.Actor // Keep the order: first we undo and then we create @@ -20,9 +55,5 @@ async function sendVideoRateChange (account: AccountModel, // Like if (likes > 0) await sendLike(actor, video, t) // Dislike - if (dislikes > 0) await sendCreateDislike(actor, video, t) -} - -export { - sendVideoRateChange + if (dislikes > 0) await sendDislike(actor, video, t) }