"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InboxManager = void 0;
const tslib_1 = require("tslib");
const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
const logger_1 = require("../../helpers/logger");
const constants_1 = require("../../initializers/constants");
const stat_manager_1 = require("../stat-manager");
const process_1 = require("./process");
class InboxManager {
    constructor() {
        this.inboxQueue = new p_queue_1.default({ concurrency: 1 });
        setInterval(() => {
            stat_manager_1.StatsManager.Instance.updateInboxWaiting(this.getActivityPubMessagesWaiting());
        }, constants_1.SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS);
    }
    addInboxMessage(param) {
        this.inboxQueue.add(() => {
            const options = { signatureActor: param.signatureActor, inboxActor: param.inboxActor };
            return (0, process_1.processActivities)(param.activities, options);
        }).catch(err => logger_1.logger.error('Error with inbox queue.', { err }));
    }
    getActivityPubMessagesWaiting() {
        return this.inboxQueue.size + this.inboxQueue.pending;
    }
    static get Instance() {
        return this.instance || (this.instance = new this());
    }
}
exports.InboxManager = InboxManager;
//# sourceMappingURL=inbox-manager.js.map