Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions platforms/pictique-api/src/services/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class ChatService {

// Filter chats that have exactly the same participants (order doesn't matter)
const sortedParticipantIds = participantIds.sort();

for (const chat of chats) {
const chatParticipantIds = chat.participants.map(p => p.id).sort();

if (chatParticipantIds.length === sortedParticipantIds.length &&
chatParticipantIds.every((id, index) => id === sortedParticipantIds[index])) {
return chat;
Expand Down Expand Up @@ -162,11 +162,7 @@ export class ChatService {
});

const savedMessage = await this.messageRepository.save(message);

// Update the chat's updatedAt timestamp to reflect the latest message
chat.updatedAt = new Date();
await this.chatRepository.save(chat);


console.log("Sent event", `chat:${chatId}`);
this.eventEmitter.emit(`chat:${chatId}`, [savedMessage]);

Expand Down Expand Up @@ -317,13 +313,13 @@ export class ChatService {
const sortedChats = chatsWithRelations.sort((a, b) => {
const aLatestMessage = a.messages[a.messages.length - 1];
const bLatestMessage = b.messages[b.messages.length - 1];

if (!aLatestMessage && !bLatestMessage) {
return b.createdAt.getTime() - a.createdAt.getTime();
}
if (!aLatestMessage) return 1;
if (!bLatestMessage) return -1;

return bLatestMessage.createdAt.getTime() - aLatestMessage.createdAt.getTime();
});

Expand Down
8 changes: 0 additions & 8 deletions platforms/pictique-api/src/services/MessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ export class MessageService {
});

const savedMessage = await this.messageRepository.save(message);

// Update the chat's updatedAt timestamp to reflect the latest message
const chat = await this.chatRepository.findOneBy({ id: chatId });
if (chat) {
chat.updatedAt = new Date();
await this.chatRepository.save(chat);
}

return savedMessage;
}

Expand Down
Loading