"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendAbuse = void 0;
const logger_1 = require("../../../helpers/logger");
const audience_1 = require("../audience");
const url_1 = require("../url");
const send_utils_1 = require("./shared/send-utils");
function sendAbuse(byActor, abuse, flaggedAccount, t) {
    if (!flaggedAccount.Actor.serverId)
        return;
    const url = (0, url_1.getLocalAbuseActivityPubUrl)(abuse);
    logger_1.logger.info('Creating job to send abuse %s.', url);
    const audience = { to: [flaggedAccount.Actor.url], cc: [] };
    const flagActivity = buildFlagActivity(url, byActor, abuse, audience);
    return t.afterCommit(() => {
        return (0, send_utils_1.unicastTo)({
            data: flagActivity,
            byActor,
            toActorUrl: flaggedAccount.Actor.getSharedInbox(),
            contextType: 'Flag'
        });
    });
}
exports.sendAbuse = sendAbuse;
function buildFlagActivity(url, byActor, abuse, audience) {
    if (!audience)
        audience = (0, audience_1.getAudience)(byActor);
    const activity = Object.assign({ id: url, actor: byActor.url }, abuse.toActivityPubObject());
    return (0, audience_1.audiencify)(activity, audience);
}
//# sourceMappingURL=send-flag.js.map