From 53ef273665f47e9bb8a625eee460c9542baa6bf7 Mon Sep 17 00:00:00 2001 From: Daniil Fadeev Date: Wed, 26 Jul 2023 19:25:15 +0300 Subject: [PATCH] notifications: Extract notification key retrieval. This commit aims to extract all logic related to obtaining notification key from the `process_notification` function into a separate `get_notification_key` function. --- web/src/notifications.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/web/src/notifications.js b/web/src/notifications.js index 6e118dc93a..a8c6b98932 100644 --- a/web/src/notifications.js +++ b/web/src/notifications.js @@ -245,11 +245,24 @@ function debug_notification_source_value(message) { blueslip.debug("Desktop notification from source " + notification_source); } +function get_notification_key(message) { + let key; + + if (message.type === "private" || message.type === "test-notification") { + key = message.display_reply_to; + } else { + const stream_name = stream_data.get_stream_name_from_id(message.stream_id); + key = message.sender_full_name + " to " + stream_name + " > " + message.topic; + } + + return key; +} + export function process_notification(notification) { let notification_object; - let key; const message = notification.message; const content = get_notification_content(message); + const key = get_notification_key(message); let other_recipients; let title = message.sender_full_name; let msg_count = 1; @@ -259,14 +272,10 @@ export function process_notification(notification) { debug_notification_source_value(message); if (message.type === "private" || message.type === "test-notification") { - key = message.display_reply_to; // Remove the sender from the list of other recipients other_recipients = `, ${message.display_reply_to}, ` .replace(`, ${message.sender_full_name}, `, ", ") .slice(", ".length, -", ".length); - } else { - const stream_name = stream_data.get_stream_name_from_id(message.stream_id); - key = message.sender_full_name + " to " + stream_name + " > " + topic; } if (notice_memory.has(key)) {