Skip to content

Commit

Permalink
fix(api): fix notifications on sent chat messages (#903)
Browse files Browse the repository at this point in the history
Co-authored-by: Johan Book <{ID}+{username}@users.noreply.github.com>
  • Loading branch information
johanbook and Johan Book authored Jul 20, 2024
1 parent 7ba7bfc commit 5aecbde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ChatMessageSentEvent } from "../../../domain/events/chat-message-sent.e
import { ChatConversation } from "../../../infrastructure/entities/chat-conversation.entity";

@EventsHandler(ChatMessageSentEvent)
export class NotifyReceiverOnPostedChatMessageHandler
export class NotifyChatOnPostedMessageHandler
implements IEventHandler<ChatMessageSentEvent>
{
constructor(
Expand Down Expand Up @@ -45,6 +45,9 @@ export class NotifyReceiverOnPostedChatMessageHandler
profileId: true,
},
},
relations: {
members: true,
},
where: {
id: event.conversationId,
},
Expand All @@ -54,7 +57,9 @@ export class NotifyReceiverOnPostedChatMessageHandler
throw new NotFoundException("Conversation not found");
}

const receivers = conversation.members.map((member) => member.profileId);
const receivers = conversation.members
.map((member) => member.profileId)
.filter((profileId) => profileId !== event.senderId);

const notification: INotification = {
data: { senderId: event.senderId },
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/features/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ProfileModule } from "src/core/profiles/profile.module";

import { CreateChatHandler } from "./application/handlers/command-handlers/create-chat-handler";
import { PostChatMessageHandler } from "./application/handlers/command-handlers/post-chat-message.handler";
import { NotifyReceiverOnPostedChatMessageHandler } from "./application/handlers/event-handlers/notify-receiver-on-posted-message.handler";
import { NotifyChatOnPostedMessageHandler } from "./application/handlers/event-handlers/notify-chat-on-posted-message.handler";
import { GetChatMessagesHandler } from "./application/handlers/query-handlers/get-chat-messages.handler";
import { GetConversationListHandler } from "./application/handlers/query-handlers/get-conversation-list.handler";
import { ChatsController } from "./client/controllers/chats.controller";
Expand All @@ -37,7 +37,7 @@ import { ChatMessage } from "./infrastructure/entities/chat-message.entity";
CreateChatHandler,
GetChatMessagesHandler,
GetConversationListHandler,
NotifyReceiverOnPostedChatMessageHandler,
NotifyChatOnPostedMessageHandler,
PostChatMessageHandler,
],
})
Expand Down

0 comments on commit 5aecbde

Please sign in to comment.