From b5a7fecea65ee311cadeeac2a45f2b7a6f654e55 Mon Sep 17 00:00:00 2001 From: LomyW <115979086+LomyW@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:27:17 +0100 Subject: [PATCH] fix: filter system messages from missed message notifications (#955) * filter out system messages * do not send notification for system messages --- web/controllers/chatNotificationController/index.ts | 3 ++- web/controllers/chatNotificationController/util.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web/controllers/chatNotificationController/index.ts b/web/controllers/chatNotificationController/index.ts index b7ffa479f..4c8c125c7 100644 --- a/web/controllers/chatNotificationController/index.ts +++ b/web/controllers/chatNotificationController/index.ts @@ -39,8 +39,9 @@ async function handleChatNotification(req: WithRawBody, res: Response): const chatType = getChatType(conversationParticipants); const isUserVerified = await verifyChatUser(recipientUser); + const onlySystemMessages = data.messages.every((m) => m.type === 'SystemMessage'); - if (isUserVerified) { + if (!onlySystemMessages && isUserVerified) { const notificationContext = await getNotificationContext(notificationBody); const notificationAction = chatType === ChatType.ONE_ON_ONE ? 'missed_one_on_one_chat_message' : 'missed_course_chat_message'; diff --git a/web/controllers/chatNotificationController/util.ts b/web/controllers/chatNotificationController/util.ts index e1afa7c2c..435bae284 100644 --- a/web/controllers/chatNotificationController/util.ts +++ b/web/controllers/chatNotificationController/util.ts @@ -45,10 +45,12 @@ export async function getNotificationContext(notificationBody: NotificationTrigg courseId = subcourse.courseId; } + const filteredMessages = messages.filter((message) => message.type !== 'SystemMessage'); + notificationContext = { sender: { firstname: firstnameSender }, conversationId: conversation.id, - message: messages[0].text, + message: filteredMessages[0].text, totalUnread: messages.length.toString(), ...(match ? { matchId: match.matchId } : {}), ...(courseId ? { courseId: courseId.toString() } : {}),