"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendVideoRateChange = exports.getLocalRateUrl = void 0;
const tslib_1 = require("tslib");
const send_1 = require("./send");
const send_dislike_1 = require("./send/send-dislike");
const url_1 = require("./url");
const videos_1 = require("./videos");
function sendVideoRateChange(account, video, likes, dislikes, t) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        if (video.isOwned())
            return (0, videos_1.federateVideoIfNeeded)(video, false, t);
        return sendVideoRateChangeToOrigin(account, video, likes, dislikes, t);
    });
}
exports.sendVideoRateChange = sendVideoRateChange;
function getLocalRateUrl(rateType, actor, video) {
    return rateType === 'like'
        ? (0, url_1.getVideoLikeActivityPubUrlByLocalActor)(actor, video)
        : (0, url_1.getVideoDislikeActivityPubUrlByLocalActor)(actor, video);
}
exports.getLocalRateUrl = getLocalRateUrl;
function sendVideoRateChangeToOrigin(account, video, likes, dislikes, t) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        if (video.isOwned())
            return;
        const actor = account.Actor;
        if (likes < 0)
            yield (0, send_1.sendUndoLike)(actor, video, t);
        if (dislikes < 0)
            yield (0, send_1.sendUndoDislike)(actor, video, t);
        if (likes > 0)
            yield (0, send_1.sendLike)(actor, video, t);
        if (dislikes > 0)
            yield (0, send_dislike_1.sendDislike)(actor, video, t);
    });
}
//# sourceMappingURL=video-rates.js.map