mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
insert_new_message: Rewrite using all_rendered_message_lists.
This replaces one of the our larger remaining blocks of code with explicit logic for message_lists.home with logic that should correct if we support maintaining a different set of rendered message lists. This should have identical behavior to the previous implementation given that all_rendered_message_lists is either just message_lists.home or that plus the current narrowed message list; can_apply_locally() is always true for the home message list, and the list === message_lists.current check is equivalent to the more complex narrow_state.active() check.
This commit is contained in:
@@ -122,33 +122,35 @@ export function insert_new_messages(messages, sent_by_this_client) {
|
|||||||
// other lists, so we always update this
|
// other lists, so we always update this
|
||||||
message_util.add_new_messages_data(messages, all_messages_data);
|
message_util.add_new_messages_data(messages, all_messages_data);
|
||||||
|
|
||||||
let render_info;
|
let need_user_to_scroll = false;
|
||||||
|
for (const list of message_lists.all_rendered_message_lists()) {
|
||||||
if (narrow_state.active()) {
|
if (!list.data.filter.can_apply_locally()) {
|
||||||
// We do this NOW even though the home view is not active,
|
// If we cannot locally calculate whether the new messages
|
||||||
// because we want the home view to load fast later.
|
// match the message list, we ask the server whether the
|
||||||
message_util.add_new_messages(messages, message_lists.home);
|
// new messages match the narrow, and use that to
|
||||||
|
// determine which new messages to add to the current
|
||||||
if (narrow_state.filter().can_apply_locally()) {
|
// message list (or display a notification).
|
||||||
render_info = message_util.add_new_messages(messages, message_lists.current);
|
maybe_add_narrowed_messages(messages, list, message_util.add_new_messages);
|
||||||
} else {
|
continue;
|
||||||
// if we cannot apply locally, we have to wait for this callback to happen to notify
|
}
|
||||||
maybe_add_narrowed_messages(
|
|
||||||
messages,
|
// Update the message list's rendering for the newly arrived messages.
|
||||||
message_lists.current,
|
const render_info = message_util.add_new_messages(messages, list);
|
||||||
message_util.add_new_messages,
|
|
||||||
);
|
// The render_info.need_user_to_scroll calculation, which
|
||||||
}
|
// looks at message feed scroll positions to see whether the
|
||||||
} else {
|
// newly arrived message will be visible, is only valid if
|
||||||
// we're in the home view, so update its list
|
// this message list is the currently visible message list.
|
||||||
render_info = message_util.add_new_messages(messages, message_lists.home);
|
const is_currently_visible = list === message_lists.current;
|
||||||
|
if (is_currently_visible && render_info && render_info.need_user_to_scroll) {
|
||||||
|
need_user_to_scroll = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sent_by_this_client) {
|
|
||||||
const need_user_to_scroll = render_info && render_info.need_user_to_scroll;
|
|
||||||
// sent_by_this_client will be true if ANY of the messages
|
// sent_by_this_client will be true if ANY of the messages
|
||||||
// were sent by this client; notifications.notify_local_mixes
|
// were sent by this client; notifications.notify_local_mixes
|
||||||
// will filter out any not sent by us.
|
// will filter out any not sent by us.
|
||||||
|
if (sent_by_this_client) {
|
||||||
notifications.notify_local_mixes(messages, need_user_to_scroll);
|
notifications.notify_local_mixes(messages, need_user_to_scroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,17 @@ const stream_list = mock_esm("../src/stream_list");
|
|||||||
const unread_ops = mock_esm("../src/unread_ops");
|
const unread_ops = mock_esm("../src/unread_ops");
|
||||||
const unread_ui = mock_esm("../src/unread_ui");
|
const unread_ui = mock_esm("../src/unread_ui");
|
||||||
|
|
||||||
message_lists.home = {};
|
message_lists.current = {
|
||||||
|
data: {
|
||||||
|
filter: {
|
||||||
|
can_apply_locally() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
message_lists.home = message_lists.current;
|
||||||
|
message_lists.all_rendered_message_lists = () => [message_lists.home, message_lists.current];
|
||||||
|
|
||||||
// And we will also test some real code, of course.
|
// And we will also test some real code, of course.
|
||||||
const message_events = zrequire("message_events");
|
const message_events = zrequire("message_events");
|
||||||
@@ -109,6 +119,7 @@ run_test("insert_message", ({override}) => {
|
|||||||
[huddle_data, "process_loaded_messages"],
|
[huddle_data, "process_loaded_messages"],
|
||||||
[message_util, "add_new_messages_data"],
|
[message_util, "add_new_messages_data"],
|
||||||
[message_util, "add_new_messages"],
|
[message_util, "add_new_messages"],
|
||||||
|
[message_util, "add_new_messages"],
|
||||||
[unread_ui, "update_unread_counts"],
|
[unread_ui, "update_unread_counts"],
|
||||||
[unread_ops, "process_visible"],
|
[unread_ops, "process_visible"],
|
||||||
[notifications, "received_messages"],
|
[notifications, "received_messages"],
|
||||||
|
|||||||
Reference in New Issue
Block a user