"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetArchivedChatsQueryHandler = exports.GetChatHistoryQueryHandler = void 0; const Logger_1 = require("../../Services/Logger"); class GetChatHistoryQueryHandler { constructor(chatRepository, chatArchiveRepository) { this.chatRepository = chatRepository; this.chatArchiveRepository = chatArchiveRepository; } async execute(query) { try { // First try to find active chat const chat = await this.chatRepository.findById(query.chatId); if (chat) { // Check authorization if (!chat.users.includes(query.userId)) { (0, Logger_1.logWarning)('Unauthorized chat history access attempt', { chatId: query.chatId, userId: query.userId }); return null; } (0, Logger_1.logAuth)('Chat history retrieved', query.userId, { chatId: query.chatId, messageCount: chat.messages.length, isArchived: false }); return { chatId: query.chatId, messages: chat.messages, isArchived: false, chatInfo: { type: chat.type, name: chat.name, gameId: chat.gameId, users: chat.users } }; } // Try to find in archives const archives = await this.chatArchiveRepository.findByChatId(query.chatId); const userArchive = archives.find(archive => archive.participants.includes(query.userId)); if (userArchive) { (0, Logger_1.logAuth)('Archived chat history retrieved', query.userId, { chatId: query.chatId, messageCount: userArchive.archivedMessages.length, isArchived: true }); return { chatId: query.chatId, messages: userArchive.archivedMessages, isArchived: true, chatInfo: { type: userArchive.chatType, name: userArchive.chatName, gameId: userArchive.gameId, users: userArchive.participants } }; } (0, Logger_1.logWarning)('Chat history not found', { chatId: query.chatId, userId: query.userId }); return null; } catch (error) { (0, Logger_1.logError)('GetChatHistoryQueryHandler error', error); return null; } } } exports.GetChatHistoryQueryHandler = GetChatHistoryQueryHandler; class GetArchivedChatsQueryHandler { constructor(chatArchiveRepository) { this.chatArchiveRepository = chatArchiveRepository; } async execute(query) { try { let archives = []; if (query.gameId) { // Get archived game chats archives = await this.chatArchiveRepository.findByGameId(query.gameId); } else { // Get all archived chats for user (would need different query) // For now, return empty - this would need a new repository method archives = []; } const result = archives .filter(archive => archive.participants.includes(query.userId)) .map(archive => ({ chatId: archive.chatId, messages: archive.archivedMessages, isArchived: true, chatInfo: { type: archive.chatType, name: archive.chatName, gameId: archive.gameId, users: archive.participants } })); (0, Logger_1.logAuth)('Archived chats retrieved', query.userId, { count: result.length, gameId: query.gameId }); return result; } catch (error) { (0, Logger_1.logError)('GetArchivedChatsQueryHandler error', error); return []; } } } exports.GetArchivedChatsQueryHandler = GetArchivedChatsQueryHandler; //# sourceMappingURL=ChatHistoryQueryHandlers.js.map