"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendView = void 0;
const tslib_1 = require("tslib");
const video_views_manager_1 = require("../../views/video-views-manager");
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 sendView(options) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { byActor, type, video, viewerIdentifier, transaction } = options;
        logger_1.logger.info('Creating job to send %s of %s.', type, video.url);
        const activityBuilder = (audience) => {
            const url = (0, url_1.getLocalVideoViewActivityPubUrl)(byActor, video, viewerIdentifier);
            return buildViewActivity({ url, byActor, video, audience, type });
        };
        return (0, send_utils_1.sendVideoRelatedActivity)(activityBuilder, { byActor, video, transaction, contextType: 'View', parallelizable: true });
    });
}
exports.sendView = sendView;
function buildViewActivity(options) {
    const { url, byActor, type, video, audience = (0, audience_1.getAudience)(byActor) } = options;
    return (0, audience_1.audiencify)({
        id: url,
        type: 'View',
        actor: byActor.url,
        object: video.url,
        expires: type === 'viewer'
            ? new Date(video_views_manager_1.VideoViewsManager.Instance.buildViewerExpireTime()).toISOString()
            : undefined
    }, audience);
}
//# sourceMappingURL=send-view.js.map