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.
This commit is contained in:
Varun Singh 2024-02-10 22:52:36 +05:30 committed by Tim Abbott
parent c8f135b97a
commit 0ec622c5f4
1 changed files with 8 additions and 17 deletions

View File

@ -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) {