mirror of https://github.com/zulip/zulip.git
narrow: Use update_current_message_list instead of set_current.
It's important to remove the focused class and remote the old message list from DOM which only happens in update_current_message_list.
This commit is contained in:
parent
3c0cb4c6a2
commit
4ccf64b02b
|
@ -537,5 +537,5 @@ export function initialize() {
|
|||
excludes_muted_topics: true,
|
||||
});
|
||||
message_lists.set_home(home_msg_list);
|
||||
message_lists.set_current(home_msg_list);
|
||||
message_lists.update_current_message_list(home_msg_list);
|
||||
}
|
||||
|
|
|
@ -55,10 +55,25 @@ export type MessageList = {
|
|||
export let home: MessageList | undefined;
|
||||
export let current: MessageList | undefined;
|
||||
|
||||
export function set_current(msg_list: MessageList): void {
|
||||
function set_current(msg_list: MessageList): void {
|
||||
// NOTE: Use update_current_message_list instead of this function.
|
||||
current = msg_list;
|
||||
}
|
||||
|
||||
export function update_current_message_list(msg_list: MessageList): void {
|
||||
if (msg_list !== home) {
|
||||
home?.view.$list.removeClass("focused-message-list");
|
||||
}
|
||||
|
||||
if (current !== home) {
|
||||
// Remove old msg list from DOM.
|
||||
current?.view.$list.remove();
|
||||
}
|
||||
|
||||
set_current(msg_list);
|
||||
current?.view.$list.addClass("focused-message-list");
|
||||
}
|
||||
|
||||
export function set_home(msg_list: MessageList): void {
|
||||
home = msg_list;
|
||||
}
|
||||
|
|
|
@ -87,20 +87,6 @@ export function save_narrow(terms) {
|
|||
changehash(new_hash);
|
||||
}
|
||||
|
||||
export function update_current_message_list(msg_list) {
|
||||
if (msg_list !== message_lists.home) {
|
||||
message_lists.home?.view.$list.removeClass("focused-message-list");
|
||||
}
|
||||
|
||||
if (message_lists.current !== message_lists.home) {
|
||||
// Remove old msg list from DOM.
|
||||
message_lists.current?.view.$list.remove();
|
||||
}
|
||||
|
||||
message_lists.set_current(msg_list);
|
||||
message_lists.current.view.$list.addClass("focused-message-list");
|
||||
}
|
||||
|
||||
export function activate(raw_terms, opts) {
|
||||
/* Main entry point for switching to a new view / message list.
|
||||
Note that for historical reasons related to the current
|
||||
|
@ -461,7 +447,7 @@ export function activate(raw_terms, opts) {
|
|||
// Show the new set of messages. It is important to set message_lists.current to
|
||||
// the view right as it's being shown, because we rely on message_lists.current
|
||||
// being shown for deciding when to condense messages.
|
||||
update_current_message_list(msg_list);
|
||||
message_lists.update_current_message_list(msg_list);
|
||||
|
||||
let then_select_offset;
|
||||
if (id_info.target_id === id_info.final_select_id) {
|
||||
|
@ -1115,7 +1101,7 @@ export function deactivate() {
|
|||
narrow_state.reset_current_filter();
|
||||
narrow_state.set_has_shown_message_list_view();
|
||||
|
||||
update_current_message_list(message_lists.home);
|
||||
message_lists.update_current_message_list(message_lists.home);
|
||||
message_lists.current.resume_reading();
|
||||
condense.condense_and_collapse(message_lists.home.view.$list.find(".message_row"));
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ const message_lists = mock_esm("../src/message_lists", {
|
|||
},
|
||||
},
|
||||
},
|
||||
set_current(msg_list) {
|
||||
update_current_message_list(msg_list) {
|
||||
message_lists.current = msg_list;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -9,6 +9,10 @@ const {page_params, realm} = require("./lib/zpage_params");
|
|||
const {Filter} = zrequire("filter");
|
||||
const {MessageList} = zrequire("message_list");
|
||||
const message_lists = zrequire("message_lists");
|
||||
message_lists.update_current_message_list = (list) => {
|
||||
message_lists.current = list;
|
||||
};
|
||||
|
||||
const popover_menus_data = zrequire("popover_menus_data");
|
||||
const people = zrequire("people");
|
||||
const compose_state = zrequire("compose_state");
|
||||
|
@ -135,7 +139,7 @@ test("my_message_all_actions", () => {
|
|||
// Get message with maximum permissions available
|
||||
// Initialize message list
|
||||
const list = init_message_list();
|
||||
message_lists.set_current(list);
|
||||
message_lists.update_current_message_list(list);
|
||||
|
||||
// Assume message has been previously edited.
|
||||
// Message is sent by me, and is a stream. I should have all permissions to this message.
|
||||
|
@ -185,7 +189,7 @@ test("not_my_message_view_actions", () => {
|
|||
// Get message that is only viewable
|
||||
|
||||
const list = init_message_list();
|
||||
message_lists.set_current(list);
|
||||
message_lists.update_current_message_list(list);
|
||||
|
||||
// Message is sent by somebody else and is a stream with previous history.
|
||||
// I should only be able to view this message with no edit/move permissions.
|
||||
|
@ -225,7 +229,7 @@ test("not_my_message_view_source_and_move", () => {
|
|||
// Get message that is movable with viewable source
|
||||
|
||||
const list = init_message_list();
|
||||
message_lists.set_current(list);
|
||||
message_lists.update_current_message_list(list);
|
||||
|
||||
// Message tests edge case where message it sent by someone else.
|
||||
// Message is movable, however--I should have only view permissions with the exception of moving the message.
|
||||
|
|
Loading…
Reference in New Issue