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.

message_list_data: Potentially return undefined in first_unread_message_id.

evykassirer0f1fa8e15903
diff --git a/web/src/message_list.js b/web/src/message_list.js
index 480ad8c863c..6cd9df59b10 100644
--- a/web/src/message_list.js
+++ b/web/src/message_list.js
@@ -1,5 +1,6 @@
import autosize from "autosize";
import $ from "jquery";
+import assert from "minimalistic-assert";
import {all_messages_data} from "./all_messages_data";
import * as blueslip from "./blueslip";
@@ -131,7 +132,9 @@ export class MessageList {
// message. Regardless of whether the messages are new or
// old, we want to select a message as though we just
// entered this view.
- this.select_id(this.first_unread_message_id(), {then_scroll: true, use_closest: true});
+ const first_unread_message_id = this.first_unread_message_id();
+ assert(first_unread_message_id !== undefined);
+ this.select_id(first_unread_message_id, {then_scroll: true, use_closest: true});
}
return render_info;
diff --git a/web/src/message_list_data.ts b/web/src/message_list_data.ts
index 9f013de07be..3239b25bda3 100644
--- a/web/src/message_list_data.ts
+++ b/web/src/message_list_data.ts
@@ -1,5 +1,3 @@
-import assert from "minimalistic-assert";
-
import * as blueslip from "./blueslip";
import {FetchStatus} from "./fetch_status";
import type {Filter} from "./filter";
@@ -285,7 +283,7 @@ export class MessageListData {
this._items = this.unmuted_messages(this._all_items);
}
- first_unread_message_id(): number {
+ first_unread_message_id(): number | undefined {
const first_unread = this._items.find((message) => unread.message_unread(message));
if (first_unread) {
@@ -293,9 +291,7 @@ export class MessageListData {
}
// if no unread, return the bottom message
- const last = this.last();
- assert(last !== undefined);
- return last.id;
+ return this.last()?.id;
}
has_unread_messages(): boolean {
diff --git a/web/src/narrow.js b/web/src/narrow.js
index 44c3a1cff8f..2afe283850f 100644
--- a/web/src/narrow.js
+++ b/web/src/narrow.js
@@ -1,5 +1,6 @@
import * as Sentry from "@sentry/browser";
import $ from "jquery";
+import assert from "minimalistic-assert";
import {all_messages_data} from "./all_messages_data";
import * as blueslip from "./blueslip";
@@ -730,6 +731,8 @@ export function update_selection(opts) {
if (msg_id === undefined) {
msg_id = message_lists.current.first_unread_message_id();
}
+ // There should be something since it's not visibly empty.
+ assert(msg_id !== undefined);
const preserve_pre_narrowing_screen_position =
message_lists.current.get(msg_id) !== undefined && select_offset !== undefined;
@@ -1122,6 +1125,7 @@ export function deactivate() {
}
message_id_to_select = message_lists.current.selected_id();
}
+ assert(message_id_to_select !== undefined);
message_lists.current.select_id(message_id_to_select, select_opts);
}