Skip to content

Commit

Permalink
fix: filter system messages from missed message notifications (#955)
Browse files Browse the repository at this point in the history
* filter out system messages

* do not send notification for system messages
  • Loading branch information
LomyW authored Jan 23, 2024
1 parent 69cbbc9 commit b5a7fec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion web/controllers/chatNotificationController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ async function handleChatNotification(req: WithRawBody<Request>, 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';
Expand Down
4 changes: 3 additions & 1 deletion web/controllers/chatNotificationController/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() } : {}),
Expand Down

0 comments on commit b5a7fec

Please sign in to comment.