Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

eslint: Fix @typescript-eslint/prefer-optional-chain.

Anders Kaseorg26ae5339858f
diff --git a/web/src/activity.ts b/web/src/activity.ts
index e29cee9b8f5..f235c521d5b 100644
--- a/web/src/activity.ts
+++ b/web/src/activity.ts
@@ -40,7 +40,7 @@ const DEFAULT_IDLE_TIMEOUT_MS = 5 * 60 * 1000;
// should be true. When a server-initiated reload happens, however,
// it should be initialized to false. We handle this with a check for
// whether the window is focused at initialization time.
-export let client_is_active = document.hasFocus && document.hasFocus();
+export let client_is_active = document.hasFocus();
// new_user_input is a more strict version of client_is_active used
// primarily for analytics. We initialize this to true, to count new
diff --git a/web/src/people.ts b/web/src/people.ts
index 4ce964e3431..1fb76b73bb4 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -792,7 +792,7 @@ export function sender_is_guest(message: Message): boolean {
export function is_valid_bot_user(user_id: number): boolean {
const user = maybe_get_user_by_id(user_id, true);
- return user !== undefined && user.is_bot;
+ return user?.is_bot ?? false;
}
export function should_add_guest_user_indicator(user_id: number): boolean {
diff --git a/web/src/reactions.ts b/web/src/reactions.ts
index edc896d5735..8a77c952429 100644
--- a/web/src/reactions.ts
+++ b/web/src/reactions.ts
@@ -36,10 +36,7 @@ export function current_user_has_reacted_to_emoji(message: Message, local_id: st
set_clean_reactions(message);
const clean_reaction_object = message.clean_reactions.get(local_id);
- return (
- clean_reaction_object !== undefined &&
- clean_reaction_object.user_ids.includes(current_user.user_id)
- );
+ return clean_reaction_object?.user_ids.includes(current_user.user_id) ?? false;
}
function get_message(message_id: number): Message | undefined {
@@ -281,7 +278,7 @@ export function add_reaction(event: ReactionEvent): void {
const local_id = get_local_reaction_id(event);
const user_id = event.user_id;
let clean_reaction_object = message.clean_reactions.get(local_id);
- if (clean_reaction_object && clean_reaction_object.user_ids.includes(user_id)) {
+ if (clean_reaction_object?.user_ids.includes(user_id)) {
return;
}
diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js
index 59677d32207..e67da42e8c4 100644
--- a/web/tests/hotkey.test.js
+++ b/web/tests/hotkey.test.js
@@ -30,7 +30,9 @@ set_global("navigator", {
});
// jQuery stuff should go away if we make an initialize() method.
-set_global("document", "document-stub");
+set_global("document", {
+ hasFocus: () => false,
+});
const activity_ui = mock_esm("../src/activity_ui");
const browser_history = mock_esm("../src/browser_history");