From 0ec622c5f42a47efe48ae9bff6004a6aa714d972 Mon Sep 17 00:00:00 2001 From: Varun Singh Date: Sat, 10 Feb 2024 22:52:36 +0530 Subject: [PATCH] typing_events: Refactor 'get_key' function. The function body contains only two conditionals, so the 'switch' statements can be replaced with simple 'if's that return immediately, thus making the code block cleaner. --- web/src/typing_events.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/web/src/typing_events.js b/web/src/typing_events.js index 32dd6343bf..4f8d0a3b1d 100644 --- a/web/src/typing_events.js +++ b/web/src/typing_events.js @@ -2,7 +2,6 @@ import $ from "jquery"; import render_typing_notifications from "../templates/typing_notifications.hbs"; -import * as blueslip from "./blueslip"; import * as narrow_state from "./narrow_state"; import {page_params} from "./page_params"; import * as people from "./people"; @@ -78,23 +77,15 @@ export function render_notifications_for_narrow() { } function get_key(event) { - let key; - let recipients; - switch (event.message_type) { - case "stream": - key = typing_data.get_topic_key(event.stream_id, event.topic); - break; - case "direct": - recipients = event.recipients.map((user) => user.user_id); - recipients.sort(); - - key = typing_data.get_direct_message_conversation_key(recipients); - break; - default: - blueslip.error("Unexpected message_type in typing event: " + event.message_type); - break; + if (event.message_type === "stream") { + return typing_data.get_topic_key(event.stream_id, event.topic); } - return key; + if (event.message_type === "direct") { + const recipients = event.recipients.map((user) => user.user_id); + recipients.sort(); + return typing_data.get_direct_message_conversation_key(recipients); + } + throw new Error("Invalid typing notification type", event); } export function hide_notification(event) {