фикс реадктирования сообщений

This commit is contained in:
Professional 2025-05-22 00:37:45 +07:00
parent e147959928
commit b2264d834b
2 changed files with 14 additions and 1 deletions

View File

@ -34,6 +34,9 @@ const io = new Server(server, { // <--- Инициализация socket.io
}
});
// Сделать экземпляр io доступным в запросах
app.set('io', io);
// Подключение к базе данных - проверяем, что импортировали функцию
if (typeof connectDBModule === 'function') {
try {
@ -95,6 +98,16 @@ io.on("connection", (socket) => {
return activeUsers.find(u => u.userId === userId);
};
socket.on("joinConversationRoom", (roomId) => {
socket.join(roomId);
console.log(`[Socket.IO] User ${socket.id} joined room ${roomId}`);
});
socket.on("leaveConversationRoom", (roomId) => {
socket.leave(roomId);
console.log(`[Socket.IO] User ${socket.id} left room ${roomId}`);
});
// Отправка сообщения
socket.on("sendMessage", async ({ senderId, receiverId, text, clientConversationId }) => { // Добавлен clientConversationId, async
console.log(`"[Socket.IO] Получено сообщение от ${senderId} для ${receiverId}: "${text}" (попытка для диалога: ${clientConversationId})"`);

View File

@ -33,7 +33,7 @@
<p class="mb-0">{{ item.data.text }}</p>
<small class="message-timestamp text-muted">
{{ formatMessageTimestamp(item.data.createdAt) }}
<span v-if="item.data.isEdited && item.data.sender?._id === currentUser?._id" class="ms-1 fst-italic">(изменено)</span>
<span v-if="item.data.isEdited" class="ms-1 fst-italic">(изменено)</span>
<span v-if="item.data.sender?._id === currentUser?._id && item.data.isSending" class="ms-1 fst-italic">(отправка...)</span>
<span v-if="item.data.sender?._id === currentUser?._id && !item.data.isSending" class="ms-1">
<i :class="getMessageStatusIcon(item.data)"></i>