Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_list_view: Rerender every recipient bar in rerender_messages.
Shubham Padiad6c88b4f4f37
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.tsindex cc87ea1e5ea..40ce1a6444d 100644--- a/web/src/message_list_view.ts+++ b/web/src/message_list_view.ts@@ -1605,37 +1605,20 @@ export class MessageListView {);}- _rerender_header(message_containers: MessageContainer[]): void {- // Given a list of messages that are in the **same** message group,- // rerender the header / recipient bar of the messages. This method- // should only be called with rerender_messages as the rerendered- // header may need to be updated for the "sticky_header" class.- if (message_containers.length === 0) {- return;- }-- const $first_row = this.get_row(message_containers[0]!.msg.id);-- // We may not have the row if the stream or topic was muted- if ($first_row.length === 0) {- return;- }-- const $recipient_row = rows.get_message_recipient_row($first_row);- const $header = $recipient_row.find(".message_header");- const message_group_id = $recipient_row.attr("id")!;-- // Since there might be multiple dates within the message- // group, it's important to look up the original/full message- // group rather than doing an artificial rerendering of the- // message header from the set of message containers passed in- // here.+ _rerender_header(message_group_id: string): void {+ // Rerender the header / recipient bar of the given message group,+ // rebuilding it from the authoritative group looked up below. This+ // method should only be called with rerender_messages as the+ // rerendered header may need to be updated for the "sticky_header"+ // class.const group = this._find_message_group(message_group_id);if (group === undefined) {blueslip.error("Could not find message group for rerendering headers");return;}+ const $header = $(`#${CSS.escape(message_group_id)}`).find(".message_header");+// TODO: It's possible that we no longer need this populate// call; it was introduced in an earlier version of this code// where we constructed an artificial message group for this@@ -1759,29 +1742,28 @@ export class MessageListView {}}- const message_groups = [];- let current_group = [];+ // Rerender each message row, collecting the distinct recipient+ // bars they belong to by their row's rendered group id. The+ // messages can span several bars -- even bars that share a+ // recipient -- so the group id is what distinguishes the bars.const rerendered_elements: HTMLElement[] = [];-+ const rerendered_group_ids = new Set<string>();for (const message_container of message_containers) {- if (- current_group.length === 0 ||- same_recipient(current_group.at(-1), message_container)- ) {- current_group.push(message_container);- } else {- message_groups.push(current_group);- current_group = [];- }const $rendered = this._rerender_message(message_container, {message_content_edited,is_revealed: false,});rerendered_elements.push(...$rendered);- }-- if (current_group.length > 0) {- message_groups.push(current_group);+ const $row = this.get_row(message_container.msg.id);+ // The row may be absent, e.g. for a muted stream or topic, in+ // which case there is no recipient bar to rerender.+ if ($row.length === 0) {+ continue;+ }+ const message_group_id = rows.get_message_recipient_row($row).attr("id");+ if (message_group_id !== undefined) {+ rerendered_group_ids.add(message_group_id);+ }}// Only the current message list needs its condense/collapse@@ -1792,8 +1774,10 @@ export class MessageListView {condense.condense_and_collapse($(rerendered_elements));}- for (const messages_in_group of message_groups) {- this._rerender_header(messages_in_group);+ // Now that every row is rerendered, rerender each affected bar's+ // header once.+ for (const message_group_id of rerendered_group_ids) {+ this._rerender_header(message_group_id);}if (message_lists.current === this.list && narrow_state.is_message_feed_visible()) {diff --git a/web/tests/message_list_view.test.cjs b/web/tests/message_list_view.test.cjsindex feb95c973fe..30c82bef1fb 100644--- a/web/tests/message_list_view.test.cjs+++ b/web/tests/message_list_view.test.cjs@@ -303,6 +303,52 @@ test("message_edited_vars", () => {})();});+test("rerender_messages rebuilds every distinct recipient bar", () => {+ // A user can show up in several recipient bars at once -- e.g. DMs+ // with the same user spread through Combined feed or search views.+ // When that user is renamed, rerender_messages gets all their+ // messages together and must rebuild every one of those bars, not+ // just the first. The bars share a recipient, so we identify each bar+ // by its rendered group id rather than by recipient.+ const view = new MessageListView({id: 1}, true, true);++ const dm1 = {msg: {id: 1, type: "private", to_user_ids: "5"}};+ const dm2 = {msg: {id: 2, type: "private", to_user_ids: "5"}};+ // dm3 has a container but no rendered row (e.g. a muted stream or+ // topic), so there is no recipient bar to rebuild for it.+ const dm3 = {msg: {id: 3, type: "private", to_user_ids: "5"}};+ view.message_containers = new Map([+ [1, dm1],+ [2, dm2],+ [3, dm3],+ ]);++ // dm1 and dm2 share a recipient but render in different bars; dm3 has+ // no row. The stub row mirrors how rows.get_message_recipient_row+ // reads the bar id from the DOM, and returns an empty set (length 0)+ // for the unrendered message -- which must be skipped before any DOM+ // lookup.+ const group_id_by_msg_id = {1: "group-A", 2: "group-B"};+ view.get_row = (id) => {+ const group_id = group_id_by_msg_id[id];+ if (group_id === undefined) {+ return {length: 0};+ }+ return {length: 1, parent: () => ({expectOne: () => ({attr: () => group_id})})};+ };++ view._rerender_message = () => [];+ const rerendered_group_ids = [];+ view._rerender_header = (message_group_id) => {+ rerendered_group_ids.push(message_group_id);+ };++ view.rerender_messages([dm1.msg, dm2.msg, dm3.msg]);++ // One header rerender per distinct bar; the rowless message is skipped.+ assert.deepEqual(rerendered_group_ids, ["group-A", "group-B"]);+});+test("muted_message_vars", () => {// This verifies that the variables for muted/hidden messages are set// correctly.