66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.RestoreChatCommandHandler = exports.ArchiveChatCommandHandler = void 0;
|
|
const ChatAggregate_1 = require("../../../Domain/Chat/ChatAggregate");
|
|
const Logger_1 = require("../../Services/Logger");
|
|
class ArchiveChatCommandHandler {
|
|
constructor(chatRepository) {
|
|
this.chatRepository = chatRepository;
|
|
}
|
|
async execute(command) {
|
|
try {
|
|
const chat = await this.chatRepository.findById(command.chatId);
|
|
if (!chat) {
|
|
throw new Error('Chat not found');
|
|
}
|
|
await this.chatRepository.archiveChat(chat);
|
|
(0, Logger_1.logAuth)('Chat archived manually', undefined, {
|
|
chatId: command.chatId,
|
|
chatType: chat.type,
|
|
messageCount: chat.messages.length
|
|
});
|
|
return true;
|
|
}
|
|
catch (error) {
|
|
(0, Logger_1.logError)('ArchiveChatCommandHandler error', error);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
exports.ArchiveChatCommandHandler = ArchiveChatCommandHandler;
|
|
class RestoreChatCommandHandler {
|
|
constructor(chatRepository) {
|
|
this.chatRepository = chatRepository;
|
|
}
|
|
async execute(command) {
|
|
try {
|
|
const archive = await this.chatRepository.getArchivedChat(command.chatId);
|
|
if (!archive) {
|
|
throw new Error('Archived chat not found');
|
|
}
|
|
// Game chats cannot be restored, only viewed
|
|
if (archive.chatType === ChatAggregate_1.ChatType.GAME) {
|
|
(0, Logger_1.logWarning)('Attempt to restore game chat blocked', {
|
|
chatId: command.chatId,
|
|
chatType: archive.chatType
|
|
});
|
|
return false;
|
|
}
|
|
const restoredChat = await this.chatRepository.restoreFromArchive(command.chatId);
|
|
if (!restoredChat) {
|
|
throw new Error('Failed to restore chat from archive');
|
|
}
|
|
(0, Logger_1.logAuth)('Chat restored from archive', undefined, {
|
|
chatId: command.chatId,
|
|
messageCount: archive.archivedMessages.length
|
|
});
|
|
return true;
|
|
}
|
|
catch (error) {
|
|
(0, Logger_1.logError)('RestoreChatCommandHandler error', error);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
exports.RestoreChatCommandHandler = RestoreChatCommandHandler;
|
|
//# sourceMappingURL=ChatArchiveCommandHandlers.js.map
|