From 043b43f044a19019a197bf323e375c33b68ab3f0 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 24 Oct 2023 17:28:24 -0700 Subject: [PATCH] typing_status: Remove unchecked casts in same_recipient. Signed-off-by: Anders Kaseorg --- web/shared/src/typing_status.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/web/shared/src/typing_status.ts b/web/shared/src/typing_status.ts index 2492822fcd..dc1a50419c 100644 --- a/web/shared/src/typing_status.ts +++ b/web/shared/src/typing_status.ts @@ -18,13 +18,6 @@ type TypingStatusState = { idle_timer: ReturnType; }; -function message_type(recipient: Recipient): "direct" | "stream" { - if (Array.isArray(recipient)) { - return "direct"; - } - return "stream"; -} - function lower_same(a: string, b: string): boolean { return a.toLowerCase() === b.toLowerCase(); } @@ -39,13 +32,12 @@ function same_recipient(a: Recipient | null, b: Recipient | null): boolean { return false; } - if (message_type(a) === "direct" && message_type(b) === "direct") { + if (Array.isArray(a) && Array.isArray(b)) { + // direct message recipients return _.isEqual(a, b); - } else if (message_type(a) === "stream" && message_type(b) === "stream") { - // type assertions to avoid linter error - const aStreamTopic = a as StreamTopic; - const bStreamTopic = b as StreamTopic; - return same_stream_and_topic(aStreamTopic, bStreamTopic); + } else if (!Array.isArray(a) && !Array.isArray(b)) { + // stream recipients + return same_stream_and_topic(a, b); } return false;