"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processActivityPubParallelHttpBroadcast = exports.processActivityPubHttpSequentialBroadcast = void 0;
const tslib_1 = require("tslib");
const send_1 = require("../../activitypub/send");
const actor_follow_health_cache_1 = require("../../actor-follow-health-cache");
const parent_process_1 = require("../../worker/parent-process");
const logger_1 = require("../../../helpers/logger");
function processActivityPubHttpSequentialBroadcast(job) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        logger_1.logger.info('Processing ActivityPub broadcast in job %s.', job.id);
        const requestOptions = yield buildRequestOptions(job.data);
        const { badUrls, goodUrls } = yield (0, parent_process_1.sequentialHTTPBroadcastFromWorker)({ uris: job.data.uris, requestOptions });
        return actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls);
    });
}
exports.processActivityPubHttpSequentialBroadcast = processActivityPubHttpSequentialBroadcast;
function processActivityPubParallelHttpBroadcast(job) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        logger_1.logger.info('Processing ActivityPub parallel broadcast in job %s.', job.id);
        const requestOptions = yield buildRequestOptions(job.data);
        const { badUrls, goodUrls } = yield (0, parent_process_1.parallelHTTPBroadcastFromWorker)({ uris: job.data.uris, requestOptions });
        return actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls);
    });
}
exports.processActivityPubParallelHttpBroadcast = processActivityPubParallelHttpBroadcast;
function buildRequestOptions(payload) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const body = yield (0, send_1.computeBody)(payload);
        const httpSignatureOptions = yield (0, send_1.buildSignedRequestOptions)(payload);
        return {
            method: 'POST',
            json: body,
            httpSignature: httpSignatureOptions,
            headers: (0, send_1.buildGlobalHeaders)(body)
        };
    });
}
//# sourceMappingURL=activitypub-http-broadcast.js.map