https://project.mdnd-it.cc/work_packages/94
This commit is contained in:
2025-08-23 04:25:28 +02:00
parent 725516ad6c
commit 19cfa031d0
25823 changed files with 1095587 additions and 2801760 deletions
@@ -0,0 +1,13 @@
import { ArchiveChatCommand, RestoreChatCommand } from './ChatCommands';
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
export declare class ArchiveChatCommandHandler {
private chatRepository;
constructor(chatRepository: IChatRepository);
execute(command: ArchiveChatCommand): Promise<boolean>;
}
export declare class RestoreChatCommandHandler {
private chatRepository;
constructor(chatRepository: IChatRepository);
execute(command: RestoreChatCommand): Promise<boolean>;
}
//# sourceMappingURL=ChatArchiveCommandHandlers.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatArchiveCommandHandlers.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/ChatArchiveCommandHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAI9E,qBAAa,yBAAyB;IACtB,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,eAAe;IAE7C,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAsB/D;AAED,qBAAa,yBAAyB;IACtB,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,eAAe;IAE7C,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAiC/D"}
@@ -0,0 +1,66 @@
"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
@@ -0,0 +1 @@
{"version":3,"file":"ChatArchiveCommandHandlers.js","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/ChatArchiveCommandHandlers.ts"],"names":[],"mappings":";;;AAEA,sEAA8D;AAC9D,kDAAsE;AAEtE,MAAa,yBAAyB;IAClC,YAAoB,cAA+B;QAA/B,mBAAc,GAAd,cAAc,CAAiB;IAAG,CAAC;IAEvD,KAAK,CAAC,OAAO,CAAC,OAA2B;QACrC,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,IAAI,EAAE,CAAC;gBACR,MAAM,IAAI,KAAK,CAAC,gB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IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAC3D,CAAC;YAED,IAAA,gBAAO,EAAC,4BAA4B,EAAE,SAAS,EAAE;gBAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,YAAY,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM;aAChD,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QAEhB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAA,iBAAQ,EAAC,iCAAiC,EAAE,KAAc,CAAC,CAAC;YAC5D,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ;AApCD,8DAoCC"}
@@ -0,0 +1,19 @@
export interface CreateChatCommand {
type: 'direct' | 'group' | 'game';
name?: string;
gameId?: string;
createdBy: string;
userIds: string[];
}
export interface SendMessageCommand {
chatId: string;
userId: string;
message: string;
}
export interface ArchiveChatCommand {
chatId: string;
}
export interface RestoreChatCommand {
chatId: string;
}
//# sourceMappingURL=ChatCommands.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatCommands.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/ChatCommands.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ChatCommands.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatCommands.js","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/ChatCommands.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
import { CreateChatCommand } from './ChatCommands';
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
import { IUserRepository } from '../../../Domain/IRepository/IUserRepository';
import { ChatAggregate } from '../../../Domain/Chat/ChatAggregate';
export declare class CreateChatCommandHandler {
private chatRepository;
private userRepository;
constructor(chatRepository: IChatRepository, userRepository: IUserRepository);
execute(command: CreateChatCommand): Promise<ChatAggregate | null>;
}
//# sourceMappingURL=CreateChatCommandHandler.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"CreateChatCommandHandler.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/CreateChatCommandHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAY,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAI7E,qBAAa,wBAAwB;IAE7B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,cAAc;gBADd,cAAc,EAAE,eAAe,EAC/B,cAAc,EAAE,eAAe;IAGrC,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAuE3E"}
@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateChatCommandHandler = void 0;
const ChatAggregate_1 = require("../../../Domain/Chat/ChatAggregate");
const UserAggregate_1 = require("../../../Domain/User/UserAggregate");
const Logger_1 = require("../../Services/Logger");
class CreateChatCommandHandler {
constructor(chatRepository, userRepository) {
this.chatRepository = chatRepository;
this.userRepository = userRepository;
}
async execute(command) {
try {
// Validate creator exists
const creator = await this.userRepository.findById(command.createdBy);
if (!creator) {
throw new Error('Creator not found');
}
// For group chats, check if creator is premium
if (command.type === 'group' && creator.state !== UserAggregate_1.UserState.VERIFIED_PREMIUM) {
throw new Error('Premium subscription required to create groups');
}
// Validate all target users exist
const targetUsers = await Promise.all(command.userIds.map(id => this.userRepository.findById(id)));
if (targetUsers.some(user => !user)) {
throw new Error('One or more target users not found');
}
// For direct chats, check if already exists
if (command.type === 'direct' && command.userIds.length === 1) {
const existingChats = await this.chatRepository.findByUserId(command.createdBy);
const existingDirectChat = existingChats.find(chat => chat.type === ChatAggregate_1.ChatType.DIRECT &&
chat.users.length === 2 &&
chat.users.includes(command.userIds[0]));
if (existingDirectChat) {
return existingDirectChat;
}
}
// For game chats, check if already exists
if (command.type === 'game' && command.gameId) {
const existingGameChat = await this.chatRepository.findByGameId(command.gameId);
if (existingGameChat) {
return existingGameChat;
}
}
// Create chat
const chatData = {
type: command.type,
name: command.name,
gameId: command.gameId,
createdBy: command.createdBy,
users: [command.createdBy, ...command.userIds],
messages: [],
lastActivity: new Date()
};
const chat = await this.chatRepository.create(chatData);
(0, Logger_1.logAuth)('Chat created successfully', command.createdBy, {
chatId: chat.id,
chatType: command.type,
participantCount: chat.users.length,
gameId: command.gameId
});
return chat;
}
catch (error) {
(0, Logger_1.logError)('CreateChatCommandHandler error', error);
return null;
}
}
}
exports.CreateChatCommandHandler = CreateChatCommandHandler;
//# sourceMappingURL=CreateChatCommandHandler.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CreateChatCommandHandler.js","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/CreateChatCommandHandler.ts"],"names":[],"mappings":";;;AAGA,sEAA6E;AAC7E,sEAA+D;AAC/D,kDAA0D;AAE1D,MAAa,wBAAwB;IACjC,YACY,cAA+B,EAC/B,cAA+B;QAD/B,mBAAc,GAAd,cAAc,CAAiB;QAC/B,mBAAc,GAAd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E,KAAc,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AA7ED,4DA6EC"}
@@ -0,0 +1,10 @@
import { SendMessageCommand } from './ChatCommands';
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
import { Message } from '../../../Domain/Chat/ChatAggregate';
export declare class SendMessageCommandHandler {
private chatRepository;
constructor(chatRepository: IChatRepository);
execute(command: SendMessageCommand): Promise<Message | null>;
private pruneMessages;
}
//# sourceMappingURL=SendMessageCommandHandler.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"SendMessageCommandHandler.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/SendMessageCommandHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAI7D,qBAAa,yBAAyB;IACtB,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,eAAe;IAE7C,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAiDnE,OAAO,CAAC,aAAa;CAyBxB"}
@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendMessageCommandHandler = void 0;
const Logger_1 = require("../../Services/Logger");
const uuid_1 = require("uuid");
class SendMessageCommandHandler {
constructor(chatRepository) {
this.chatRepository = chatRepository;
}
async execute(command) {
try {
// Validate message is non-empty string
if (typeof command.message !== 'string' || !command.message.trim()) {
throw new Error('Message must be a non-empty string');
}
const chat = await this.chatRepository.findById(command.chatId);
if (!chat) {
throw new Error('Chat not found');
}
// Check if user is member of this chat
if (!chat.users.includes(command.userId)) {
throw new Error('User is not a member of this chat');
}
// Create message
const message = {
id: (0, uuid_1.v4)(),
date: new Date(),
userid: command.userId,
text: command.message.trim()
};
// Manage message history (keep last 10 per user, up to 2 weeks)
let updatedMessages = [...chat.messages, message];
updatedMessages = this.pruneMessages(updatedMessages);
// Update chat
await this.chatRepository.update(command.chatId, {
messages: updatedMessages,
lastActivity: new Date()
});
(0, Logger_1.logAuth)('Message sent successfully', command.userId, {
chatId: command.chatId,
messageLength: command.message.length,
totalMessages: updatedMessages.length
});
return message;
}
catch (error) {
(0, Logger_1.logError)('SendMessageCommandHandler error', error);
return null;
}
}
pruneMessages(messages) {
const twoWeeksAgo = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000);
// Remove messages older than 2 weeks
let prunedMessages = messages.filter(msg => new Date(msg.date) > twoWeeksAgo);
// Group by user and keep last 10 messages per user
const messagesByUser = new Map();
prunedMessages.forEach(msg => {
if (!messagesByUser.has(msg.userid)) {
messagesByUser.set(msg.userid, []);
}
messagesByUser.get(msg.userid).push(msg);
});
// Keep only last 10 messages per user
const finalMessages = [];
messagesByUser.forEach((userMessages, userId) => {
const last10 = userMessages.slice(-10);
finalMessages.push(...last10);
});
// Sort by date
return finalMessages.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
}
}
exports.SendMessageCommandHandler = SendMessageCommandHandler;
//# sourceMappingURL=SendMessageCommandHandler.js.map
@@ -0,0 +1 @@
{"version":3,"file":"SendMessageCommandHandler.js","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/SendMessageCommandHandler.ts"],"names":[],"mappings":";;;AAGA,kDAA0D;AAC1D,+BAAoC;AAEpC,MAAa,yBAAyB;IAClC,YAAoB,cAA+B;QAA/B,mBAAc,GAAd,cAAc,CAAiB;IAAG,CAAC;IAEvD,KAAK,CAAC,OAAO,CAAC,OAA2B;QACrC,IAAI,CAAC;YACD,uCAAuC;YACvC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;gBACjE,MAAM,IAAI,KAAK,CAAC,oCAAoC,C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CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACjG,CAAC;CACJ;AA7ED,8DA6EC"}
@@ -0,0 +1 @@
//# sourceMappingURL=SoftDeleteCommandHandlers.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"SoftDeleteCommandHandlers.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/SoftDeleteCommandHandlers.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=SoftDeleteCommandHandlers.js.map
@@ -0,0 +1 @@
{"version":3,"file":"SoftDeleteCommandHandlers.js","sourceRoot":"","sources":["../../../../src/Application/Chat/commands/SoftDeleteCommandHandlers.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
import { GetChatHistoryQuery, GetArchivedChatsQuery } from './ChatQueries';
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
import { IChatArchiveRepository } from '../../../Domain/IRepository/IChatArchiveRepository';
import { Message } from '../../../Domain/Chat/ChatAggregate';
interface ChatHistoryResult {
chatId: string;
messages: Message[];
isArchived: boolean;
chatInfo: {
type: string;
name: string | null;
gameId: string | null;
users: string[];
};
}
export declare class GetChatHistoryQueryHandler {
private chatRepository;
private chatArchiveRepository;
constructor(chatRepository: IChatRepository, chatArchiveRepository: IChatArchiveRepository);
execute(query: GetChatHistoryQuery): Promise<ChatHistoryResult | null>;
}
export declare class GetArchivedChatsQueryHandler {
private chatArchiveRepository;
constructor(chatArchiveRepository: IChatArchiveRepository);
execute(query: GetArchivedChatsQuery): Promise<ChatHistoryResult[]>;
}
export {};
//# sourceMappingURL=ChatHistoryQueryHandlers.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatHistoryQueryHandlers.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/ChatHistoryQueryHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oDAAoD,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAG7D,UAAU,iBAAiB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,KAAK,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACL;AAED,qBAAa,0BAA0B;IAE/B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,qBAAqB;gBADrB,cAAc,EAAE,eAAe,EAC/B,qBAAqB,EAAE,sBAAsB;IAGnD,OAAO,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAwE/E;AAED,qBAAa,4BAA4B;IACzB,OAAO,CAAC,qBAAqB;gBAArB,qBAAqB,EAAE,sBAAsB;IAE3D,OAAO,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAuC5E"}
@@ -0,0 +1,116 @@
"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
@@ -0,0 +1 @@
{"version":3,"file":"ChatHistoryQueryHandlers.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
}
export interface GetChatHistoryQuery {
chatId: string;
userId: string;
}
export interface GetArchivedChatsQuery {
userId: string;
gameId?: string;
}
//# sourceMappingURL=ChatQueries.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatQueries.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/ChatQueries.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ChatQueries.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ChatQueries.js","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/ChatQueries.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
export interface GetChatsByPageQuery {
from: number;
to: number;
includeDeleted?: boolean;
}
//# sourceMappingURL=GetChatsByPageQuery.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"GetChatsByPageQuery.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetChatsByPageQuery.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=GetChatsByPageQuery.js.map
@@ -0,0 +1 @@
{"version":3,"file":"GetChatsByPageQuery.js","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetChatsByPageQuery.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
import { GetChatsByPageQuery } from './GetChatsByPageQuery';
import { ShortChatDto } from '../../DTOs/ChatDto';
export declare class GetChatsByPageQueryHandler {
private readonly chatRepo;
constructor(chatRepo: IChatRepository);
execute(query: GetChatsByPageQuery): Promise<{
chats: ShortChatDto[];
totalCount: number;
}>;
}
//# sourceMappingURL=GetChatsByPageQueryHandler.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"GetChatsByPageQueryHandler.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetChatsByPageQueryHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,qBAAa,0BAA0B;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,eAAe;IAEhD,OAAO,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CA6ClG"}
@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetChatsByPageQueryHandler = void 0;
const ChatMapper_1 = require("../../DTOs/Mappers/ChatMapper");
const Logger_1 = require("../../Services/Logger");
class GetChatsByPageQueryHandler {
constructor(chatRepo) {
this.chatRepo = chatRepo;
}
async execute(query) {
try {
// Validate pagination parameters
if (query.from < 0 || query.to < query.from) {
throw new Error('Invalid pagination parameters');
}
const limit = query.to - query.from + 1;
if (limit > 100) {
throw new Error('Page size too large. Maximum 100 records per request');
}
(0, Logger_1.logRequest)('Get chats by page query started', undefined, undefined, {
from: query.from,
to: query.to,
includeDeleted: query.includeDeleted || false
});
const result = query.includeDeleted
? await this.chatRepo.findByPageIncludingDeleted(query.from, query.to)
: await this.chatRepo.findByPage(query.from, query.to);
(0, Logger_1.logRequest)('Get chats by page query completed', undefined, undefined, {
from: query.from,
to: query.to,
returned: result.chats.length,
totalCount: result.totalCount,
includeDeleted: query.includeDeleted || false
});
return {
chats: ChatMapper_1.ChatMapper.toShortDtoList(result.chats),
totalCount: result.totalCount
};
}
catch (error) {
(0, Logger_1.logError)('GetChatsByPageQueryHandler error', error instanceof Error ? error : new Error(String(error)));
// Re-throw validation errors as-is
if (error instanceof Error && (error.message.includes('Invalid pagination') || error.message.includes('Page size'))) {
throw error;
}
throw new Error('Failed to retrieve chats page');
}
}
}
exports.GetChatsByPageQueryHandler = GetChatsByPageQueryHandler;
//# sourceMappingURL=GetChatsByPageQueryHandler.js.map
@@ -0,0 +1 @@
{"version":3,"file":"GetChatsByPageQueryHandler.js","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetChatsByPageQueryHandler.ts"],"names":[],"mappings":";;;AAGA,8DAA2D;AAC3D,kDAA6D;AAE7D,MAAa,0BAA0B;IACrC,YAA6B,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAAG,CAAC;IAE1D,KAAK,CAAC,OAAO,CAAC,KAA0B;QACtC,IAAI,CAAC;YACH,iCAAiC;YACjC,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,CAAC;YAED,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;YAC1E,CAAC;YAED,IAAA,mBAAU,EAAC,iCAAiC,EAAE,SAAS,EAAE,SAAS,E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;gBACpH,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF;AAhDD,gEAgDC"}
@@ -0,0 +1,23 @@
import { GetUserChatsQuery } from './ChatQueries';
import { IChatRepository } from '../../../Domain/IRepository/IChatRepository';
import { IChatArchiveRepository } from '../../../Domain/IRepository/IChatArchiveRepository';
interface ChatWithMetadata {
id: string;
type: string;
name: string | null;
gameId: string | null;
users: string[];
lastActivity: Date | null;
isArchived: boolean;
messageCount: number;
unreadCount?: number;
}
export declare class GetUserChatsQueryHandler {
private chatRepository;
private chatArchiveRepository;
constructor(chatRepository: IChatRepository, chatArchiveRepository: IChatArchiveRepository);
execute(query: GetUserChatsQuery): Promise<ChatWithMetadata[]>;
private calculateUnreadMessages;
}
export {};
//# sourceMappingURL=GetUserChatsQueryHandler.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"GetUserChatsQueryHandler.d.ts","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetUserChatsQueryHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oDAAoD,CAAC;AAK5F,UAAU,gBAAgB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,wBAAwB;IAE7B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,qBAAqB;gBADrB,cAAc,EAAE,eAAe,EAC/B,qBAAqB,EAAE,sBAAsB;IAGnD,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAkEpE,OAAO,CAAC,uBAAuB;CAKlC"}
@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetUserChatsQueryHandler = void 0;
const Logger_1 = require("../../Services/Logger");
class GetUserChatsQueryHandler {
constructor(chatRepository, chatArchiveRepository) {
this.chatRepository = chatRepository;
this.chatArchiveRepository = chatArchiveRepository;
}
async execute(query) {
try {
const result = [];
// Get active chats
const activeChats = await this.chatRepository.findActiveChatsForUser(query.userId);
result.push(...activeChats.map(chat => ({
id: chat.id,
type: chat.type,
name: chat.name,
gameId: chat.gameId,
users: chat.users,
lastActivity: chat.lastActivity,
isArchived: false,
messageCount: chat.messages.length,
unreadCount: this.calculateUnreadMessages(chat, query.userId)
})));
// Get archived chats if requested
if (query.includeArchived) {
const userActiveChats = await this.chatRepository.findByUserId(query.userId);
const archivedChatIds = userActiveChats
.filter(chat => chat.archiveDate !== null)
.map(chat => chat.id);
const archives = await Promise.all(archivedChatIds.map(id => this.chatArchiveRepository.findByChatId(id)));
archives.forEach(archiveArray => {
archiveArray.forEach(archive => {
if (archive.participants.includes(query.userId)) {
result.push({
id: archive.chatId,
type: archive.chatType,
name: archive.chatName,
gameId: archive.gameId,
users: archive.participants,
lastActivity: archive.archivedAt,
isArchived: true,
messageCount: archive.archivedMessages.length,
unreadCount: 0 // Archived chats have no unread messages
});
}
});
});
}
(0, Logger_1.logAuth)('User chats retrieved', query.userId, {
activeCount: activeChats.length,
totalCount: result.length,
includeArchived: query.includeArchived
});
return result.sort((a, b) => {
if (!a.lastActivity)
return 1;
if (!b.lastActivity)
return -1;
return new Date(b.lastActivity).getTime() - new Date(a.lastActivity).getTime();
});
}
catch (error) {
(0, Logger_1.logError)('GetUserChatsQueryHandler error', error);
return [];
}
}
calculateUnreadMessages(chat, userId) {
// Simple implementation - count messages from other users
// In production, you'd store lastSeen timestamp per user per chat
return chat.messages.filter(msg => msg.userid !== userId).length;
}
}
exports.GetUserChatsQueryHandler = GetUserChatsQueryHandler;
//# sourceMappingURL=GetUserChatsQueryHandler.js.map
@@ -0,0 +1 @@
{"version":3,"file":"GetUserChatsQueryHandler.js","sourceRoot":"","sources":["../../../../src/Application/Chat/queries/GetUserChatsQueryHandler.ts"],"names":[],"mappings":";;;AAKA,kDAA0D;AAc1D,MAAa,wBAAwB;IACjC,YACY,cAA+B,EAC/B,qBAA6C;QAD7C,mBAAc,GAAd,cAAc,CAAiB;QAC/B,0BAAqB,GAArB,qBAAqB,CAAwB;IACtD,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,KAAwB;QAClC,IAAI,CAAC;YACD,MAAM,MAAM,GAAuB,EAAE,CAAC;YAEtC,mBAAmB;YACnB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACnF,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACpC,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,UAAU,EAAE,KAAK;gBACjB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAClC,WAAW,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;aAChE,CAAC,CAAC,CAAC,CAAC;YAEL,kCAAkC;YAClC,IAAI,KAAK,CAAC,eAAe,EAAE,C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