mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 22:19:48 +00:00
message_list_data: Potentially return undefined in first_unread_message_id.
This commit is contained in:
committed by
Anders Kaseorg
parent
0cf1d49fee
commit
0f1fa8e159
@@ -1,5 +1,6 @@
|
|||||||
import autosize from "autosize";
|
import autosize from "autosize";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import {all_messages_data} from "./all_messages_data";
|
import {all_messages_data} from "./all_messages_data";
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
@@ -131,7 +132,9 @@ export class MessageList {
|
|||||||
// message. Regardless of whether the messages are new or
|
// message. Regardless of whether the messages are new or
|
||||||
// old, we want to select a message as though we just
|
// old, we want to select a message as though we just
|
||||||
// entered this view.
|
// 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;
|
return render_info;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import assert from "minimalistic-assert";
|
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import {FetchStatus} from "./fetch_status";
|
import {FetchStatus} from "./fetch_status";
|
||||||
import type {Filter} from "./filter";
|
import type {Filter} from "./filter";
|
||||||
@@ -285,7 +283,7 @@ export class MessageListData {
|
|||||||
this._items = this.unmuted_messages(this._all_items);
|
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));
|
const first_unread = this._items.find((message) => unread.message_unread(message));
|
||||||
|
|
||||||
if (first_unread) {
|
if (first_unread) {
|
||||||
@@ -293,9 +291,7 @@ export class MessageListData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if no unread, return the bottom message
|
// if no unread, return the bottom message
|
||||||
const last = this.last();
|
return this.last()?.id;
|
||||||
assert(last !== undefined);
|
|
||||||
return last.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
has_unread_messages(): boolean {
|
has_unread_messages(): boolean {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as Sentry from "@sentry/browser";
|
import * as Sentry from "@sentry/browser";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import {all_messages_data} from "./all_messages_data";
|
import {all_messages_data} from "./all_messages_data";
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
@@ -730,6 +731,8 @@ export function update_selection(opts) {
|
|||||||
if (msg_id === undefined) {
|
if (msg_id === undefined) {
|
||||||
msg_id = message_lists.current.first_unread_message_id();
|
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 =
|
const preserve_pre_narrowing_screen_position =
|
||||||
message_lists.current.get(msg_id) !== undefined && select_offset !== undefined;
|
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();
|
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);
|
message_lists.current.select_id(message_id_to_select, select_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user