user_topics_ui: Rerender combined feed to make unmuted topics visible.

Since combined feed no longer contains a continuous history of
muted messages, we need to rerender it display the newly visible
messages.
This commit is contained in:
Aman Agrawal
2024-12-04 16:22:41 +05:30
committed by Tim Abbott
parent 23cd8b8564
commit 276e547824
2 changed files with 38 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import * as message_edit from "./message_edit.ts";
import * as message_events from "./message_events.js";
import * as message_lists from "./message_lists.ts";
import * as message_live_update from "./message_live_update.ts";
import * as message_view from "./message_view.ts";
import * as message_view_header from "./message_view_header.ts";
import * as muted_users_ui from "./muted_users_ui.ts";
import * as narrow_state from "./narrow_state.ts";
@@ -1028,6 +1029,7 @@ export function dispatch_normal_event(event) {
user_topics_ui.handle_topic_updates(
event,
message_events.update_current_view_for_topic_visibility(),
message_view.rerender_combined_feed,
);
// Discard cached message lists if `event` topic was / is followed.
if (

View File

@@ -2,6 +2,7 @@ import $ from "jquery";
import assert from "minimalistic-assert";
import * as inbox_util from "./inbox_util.ts";
import type {MessageList} from "./message_list.ts";
import * as message_lists from "./message_lists.ts";
import type {Message} from "./message_store.ts";
import * as narrow_state from "./narrow_state.ts";
@@ -36,7 +37,12 @@ function should_add_topic_update_delay(visibility_policy: number): boolean {
export function handle_topic_updates(
user_topic_event: ServerUserTopic,
refreshed_current_narrow = false,
rerender_combined_feed_callback?: (combined_feed_msg_list: MessageList) => void,
): void {
const was_topic_visible_in_home = user_topics.is_topic_visible_in_home(
user_topic_event.stream_id,
user_topic_event.topic_name,
);
// Update the UI after changes in topic visibility policies.
user_topics.set_user_topic(user_topic_event);
@@ -50,8 +56,24 @@ export function handle_topic_updates(
);
if (!refreshed_current_narrow) {
if (message_lists.current?.data.filter.is_in_home()) {
const is_topic_visible_in_home = user_topics.is_topic_visible_in_home(
user_topic_event.stream_id,
user_topic_event.topic_name,
);
if (
rerender_combined_feed_callback &&
!was_topic_visible_in_home &&
is_topic_visible_in_home
) {
rerender_combined_feed_callback(message_lists.current);
} else {
message_lists.current.update_muting_and_rerender();
}
} else {
message_lists.current?.update_muting_and_rerender();
}
}
},
should_add_topic_update_delay(user_topic_event.visibility_policy) ? 500 : 0,
);
@@ -83,8 +105,20 @@ export function handle_topic_updates(
// Defer updates for any background-rendered messages lists until the visible one has been updated.
for (const list of message_lists.all_rendered_message_lists()) {
if (message_lists.current !== list) {
if (list.data.filter.is_in_home()) {
const is_topic_visible_in_home = user_topics.is_topic_visible_in_home(
user_topic_event.stream_id,
user_topic_event.topic_name,
);
if (!was_topic_visible_in_home && is_topic_visible_in_home) {
message_lists.delete_message_list(list);
} else {
list.update_muting_and_rerender();
}
} else {
list.update_muting_and_rerender();
}
}
}
}, 0);
}