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: Fix incorrect usage of visible empty check.

Tim Abbott1ce17f74036f
diff --git a/web/src/message_list_data.js b/web/src/message_list_data.js
index 76f909b91cb..77e4a58d3c7 100644
--- a/web/src/message_list_data.js
+++ b/web/src/message_list_data.js
@@ -65,8 +65,7 @@ export class MessageListData {
// The message list is completely empty.
empty() {
- // BUG: This should be checking _all_items.
- return this._items.length === 0;
+ return this._all_items.length === 0;
}
// The message list appears empty, but might contain messages that hidden by muting.
@@ -78,10 +77,18 @@ export class MessageListData {
return this._items[0];
}
+ first_including_muted() {
+ return this._all_items[0];
+ }
+
last() {
return this._items.at(-1);
}
+ last_including_muted() {
+ return this._all_items.at(-1);
+ }
+
ids_greater_or_equal_than(my_id) {
const result = [];
@@ -215,11 +222,6 @@ export class MessageListData {
return messages.filter((msg) => this.get(msg.id) === undefined && predicate(msg));
}
- filter_incoming(messages) {
- const predicate = this._get_predicate();
- return messages.filter((message) => predicate(message));
- }
-
messages_filtered_for_topic_mutes(messages) {
if (!this.excludes_muted_topics) {
return [...messages];
@@ -289,29 +291,22 @@ export class MessageListData {
let bottom_messages = [];
let interior_messages = [];
- // If we're initially populating the list, save the messages in
- // bottom_messages regardless
- if (this.selected_id() === -1 && this.empty()) {
- const narrow_messages = this.filter_incoming(messages);
- bottom_messages = narrow_messages.filter((msg) => !this.get(msg.id));
- } else {
- // Filter out duplicates that are already in self, and all messages
- // that fail our filter predicate
- messages = this.valid_non_duplicated_messages(messages);
-
- for (const msg of messages) {
- // Put messages in correct order on either side of the
- // message list. This code path assumes that messages
- // is a (1) sorted, and (2) consecutive block of
- // messages that belong in this message list; those
- // facts should be ensured by the caller.
- if (this.empty() || msg.id > this.last().id) {
- bottom_messages.push(msg);
- } else if (msg.id < this.first().id) {
- top_messages.push(msg);
- } else {
- interior_messages.push(msg);
- }
+ // Filter out duplicates that are already in self, and all messages
+ // that fail our filter predicate
+ messages = this.valid_non_duplicated_messages(messages);
+
+ for (const msg of messages) {
+ // Put messages in correct order on either side of the
+ // message list. This code path assumes that messages
+ // is a (1) sorted, and (2) consecutive block of
+ // messages that belong in this message list; those
+ // facts should be ensured by the caller.
+ if (this.empty() || msg.id > this.last_including_muted().id) {
+ bottom_messages.push(msg);
+ } else if (msg.id < this.first_including_muted().id) {
+ top_messages.push(msg);
+ } else {
+ interior_messages.push(msg);
}
}