Skip to content

Commit 50f3848

Browse files
authored
hotfix: remove chat updation from services right after sending a message (#384)
1 parent 65af73e commit 50f3848

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

platforms/pictique-api/src/services/ChatService.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export class ChatService {
4343

4444
// Filter chats that have exactly the same participants (order doesn't matter)
4545
const sortedParticipantIds = participantIds.sort();
46-
46+
4747
for (const chat of chats) {
4848
const chatParticipantIds = chat.participants.map(p => p.id).sort();
49-
49+
5050
if (chatParticipantIds.length === sortedParticipantIds.length &&
5151
chatParticipantIds.every((id, index) => id === sortedParticipantIds[index])) {
5252
return chat;
@@ -162,11 +162,7 @@ export class ChatService {
162162
});
163163

164164
const savedMessage = await this.messageRepository.save(message);
165-
166-
// Update the chat's updatedAt timestamp to reflect the latest message
167-
chat.updatedAt = new Date();
168-
await this.chatRepository.save(chat);
169-
165+
170166
console.log("Sent event", `chat:${chatId}`);
171167
this.eventEmitter.emit(`chat:${chatId}`, [savedMessage]);
172168

@@ -317,13 +313,13 @@ export class ChatService {
317313
const sortedChats = chatsWithRelations.sort((a, b) => {
318314
const aLatestMessage = a.messages[a.messages.length - 1];
319315
const bLatestMessage = b.messages[b.messages.length - 1];
320-
316+
321317
if (!aLatestMessage && !bLatestMessage) {
322318
return b.createdAt.getTime() - a.createdAt.getTime();
323319
}
324320
if (!aLatestMessage) return 1;
325321
if (!bLatestMessage) return -1;
326-
322+
327323
return bLatestMessage.createdAt.getTime() - aLatestMessage.createdAt.getTime();
328324
});
329325

platforms/pictique-api/src/services/MessageService.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ export class MessageService {
2323
});
2424

2525
const savedMessage = await this.messageRepository.save(message);
26-
27-
// Update the chat's updatedAt timestamp to reflect the latest message
28-
const chat = await this.chatRepository.findOneBy({ id: chatId });
29-
if (chat) {
30-
chat.updatedAt = new Date();
31-
await this.chatRepository.save(chat);
32-
}
33-
3426
return savedMessage;
3527
}
3628

0 commit comments

Comments
 (0)