"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildAnnounceWithVideoAudience = exports.buildAnnounceActivity = exports.sendVideoAnnounce = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("../../../helpers/logger");
const audience_1 = require("../audience");
const shared_1 = require("./shared");
const send_utils_1 = require("./shared/send-utils");
function buildAnnounceWithVideoAudience(byActor, videoShare, video, t) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const announcedObject = video.url;
        const actorsInvolvedInVideo = yield (0, shared_1.getActorsInvolvedInVideo)(video, t);
        const audience = (0, shared_1.getAudienceFromFollowersOf)(actorsInvolvedInVideo);
        const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience);
        return { activity, actorsInvolvedInVideo };
    });
}
exports.buildAnnounceWithVideoAudience = buildAnnounceWithVideoAudience;
function sendVideoAnnounce(byActor, videoShare, video, transaction) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { activity, actorsInvolvedInVideo } = yield buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction);
        logger_1.logger.info('Creating job to send announce %s.', videoShare.url);
        return (0, send_utils_1.broadcastToFollowers)({
            data: activity,
            byActor,
            toFollowersOf: actorsInvolvedInVideo,
            transaction,
            actorsException: [byActor],
            contextType: 'Announce'
        });
    });
}
exports.sendVideoAnnounce = sendVideoAnnounce;
function buildAnnounceActivity(url, byActor, object, audience) {
    if (!audience)
        audience = (0, audience_1.getAudience)(byActor);
    return (0, audience_1.audiencify)({
        type: 'Announce',
        id: url,
        actor: byActor.url,
        object
    }, audience);
}
exports.buildAnnounceActivity = buildAnnounceActivity;
//# sourceMappingURL=send-announce.js.map