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_cache: Update when receiving new messages.

Aman Agrawal21b6bb988775
diff --git a/web/src/message_events.js b/web/src/message_events.js
index c8f503e97dd..d69ce07d6f1 100644
--- a/web/src/message_events.js
+++ b/web/src/message_events.js
@@ -2,7 +2,6 @@ import $ from "jquery";
import assert from "minimalistic-assert";
import * as alert_words from "./alert_words";
-import {all_messages_data} from "./all_messages_data";
import * as compose_fade from "./compose_fade";
import * as compose_notifications from "./compose_notifications";
import * as compose_recipient from "./compose_recipient";
@@ -42,10 +41,6 @@ export function insert_new_messages(messages, sent_by_this_client, deliver_local
const any_untracked_unread_messages = unread.process_loaded_messages(messages, false);
direct_message_group_data.process_loaded_messages(messages);
- // all_messages_data is the data that we use to populate
- // other lists, so we always update this
- message_util.add_new_messages_data(messages, all_messages_data);
-
let need_user_to_scroll = false;
for (const list of message_lists.all_rendered_message_lists()) {
if (!list.data.filter.can_apply_locally()) {
@@ -87,6 +82,14 @@ export function insert_new_messages(messages, sent_by_this_client, deliver_local
}
}
+ for (const msg_list_data of message_lists.non_rendered_data()) {
+ if (!msg_list_data.filter.can_apply_locally()) {
+ message_list_data_cache.remove(msg_list_data.filter);
+ } else {
+ message_util.add_new_messages_data(messages, msg_list_data);
+ }
+ }
+
// sent_by_this_client will be true if ANY of the messages
// were sent by this client; notifications.notify_local_mixes
// will filter out any not sent by us.
diff --git a/web/src/message_list_data_cache.ts b/web/src/message_list_data_cache.ts
index f9b54c409ef..c2d77a06848 100644
--- a/web/src/message_list_data_cache.ts
+++ b/web/src/message_list_data_cache.ts
@@ -88,3 +88,12 @@ export function get_superset_datasets(filter: Filter): MessageListData[] {
return [...superset_datasets, all_messages_data.all_messages_data];
}
+
+export function remove(filter: Filter): void {
+ for (const [key, cached_data] of cache.entries()) {
+ if (cached_data.filter.equals(filter)) {
+ cache.delete(key);
+ return;
+ }
+ }
+}
diff --git a/web/src/message_util.ts b/web/src/message_util.ts
index 6440661d02d..719aa9c0ea6 100644
--- a/web/src/message_util.ts
+++ b/web/src/message_util.ts
@@ -73,11 +73,12 @@ export function add_new_messages_data(
}
| undefined {
if (!msg_list_data.fetch_status.has_found_newest()) {
+ const filtered_msgs = msg_list_data.valid_non_duplicated_messages(messages);
// The reasoning in add_new_messages applies here as well;
// we're trying to maintain a data structure that's a
// contiguous range of message history, so we can't append a
// new message that might not be adjacent to that range.
- msg_list_data.fetch_status.update_expected_max_message_id(messages);
+ msg_list_data.fetch_status.update_expected_max_message_id(filtered_msgs);
return undefined;
}
return msg_list_data.add_messages(messages);
diff --git a/web/tests/example5.test.js b/web/tests/example5.test.js
index dcce6367339..a7e7fa1393d 100644
--- a/web/tests/example5.test.js
+++ b/web/tests/example5.test.js
@@ -39,6 +39,7 @@ message_lists.current = {
},
};
message_lists.all_rendered_message_lists = () => [message_lists.current];
+message_lists.non_rendered_data = () => [];
// And we will also test some real code, of course.
const message_events = zrequire("message_events");
@@ -98,7 +99,6 @@ run_test("insert_message", ({override}) => {
helper.redirect(direct_message_group_data, "process_loaded_messages");
helper.redirect(message_notifications, "received_messages");
- helper.redirect(message_util, "add_new_messages_data");
helper.redirect(message_util, "add_new_messages");
helper.redirect(stream_list, "update_streams_sidebar");
helper.redirect(unread_ops, "process_visible");
@@ -112,7 +112,6 @@ run_test("insert_message", ({override}) => {
// comes in:
assert.deepEqual(helper.events, [
[direct_message_group_data, "process_loaded_messages"],
- [message_util, "add_new_messages_data"],
[message_util, "add_new_messages"],
[unread_ui, "update_unread_counts"],
[unread_ops, "process_visible"],