"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processViewActivity = void 0;
const tslib_1 = require("tslib");
const video_views_manager_1 = require("../../views/video-views-manager");
const send_utils_1 = require("../send/shared/send-utils");
const videos_1 = require("../videos");
function processViewActivity(options) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { activity, byActor } = options;
        return processCreateView(activity, byActor);
    });
}
exports.processViewActivity = processViewActivity;
function processCreateView(activity, byActor) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const videoObject = activity.object;
        const { video } = yield (0, videos_1.getOrCreateAPVideo)({
            videoObject,
            fetchType: 'only-video',
            allowRefresh: false
        });
        const viewerExpires = activity.expires
            ? new Date(activity.expires)
            : undefined;
        yield video_views_manager_1.VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, viewerExpires });
        if (video.isOwned()) {
            const exceptions = [byActor];
            yield (0, send_utils_1.forwardVideoRelatedActivity)(activity, undefined, exceptions, video);
        }
    });
}
//# sourceMappingURL=process-view.js.map