mirror of
https://github.com/zulip/zulip.git
synced 2026-06-30 21:11:04 +08:00
user_topics: Rerender unmuted topics in Recent conversations.
Rename get_muted_topics to `get_user_topics_for_visibility_policy()`, since it works for both muting and unmuting. Additionally, inline rerender_for_muted_topic, as well as removing most of the logic to diff the sets of muted topics; the event is for a single topic being changed. Co-authored-by: Hardik Dharmani <Ddharmani99@gmail.com>
This commit is contained in:
parent
6d1efdc013
commit
dee3d7a172
@ -1,5 +1,3 @@
|
||||
import _ from "lodash";
|
||||
|
||||
import * as message_lists from "./message_lists";
|
||||
import * as overlays from "./overlays";
|
||||
import * as popover_menus from "./popover_menus";
|
||||
@ -10,8 +8,13 @@ import * as sub_store from "./sub_store";
|
||||
import * as unread_ui from "./unread_ui";
|
||||
import * as user_topics from "./user_topics";
|
||||
|
||||
export function rerender_for_muted_topic(old_muted_topics) {
|
||||
export function handle_topic_updates(user_topic_event) {
|
||||
// Update the UI after changes in topic visibility policies.
|
||||
user_topics.set_user_topic(user_topic_event);
|
||||
popover_menus.get_topic_menu_popover()?.hide();
|
||||
|
||||
stream_list.update_streams_sidebar();
|
||||
unread_ui.update_unread_counts();
|
||||
message_lists.current.update_muting_and_rerender();
|
||||
if (message_lists.current !== message_lists.home) {
|
||||
message_lists.home.update_muting_and_rerender();
|
||||
@ -19,28 +22,10 @@ export function rerender_for_muted_topic(old_muted_topics) {
|
||||
if (overlays.settings_open() && settings_muted_topics.loaded) {
|
||||
settings_muted_topics.populate_list();
|
||||
}
|
||||
|
||||
// We only update those topics which could have been affected, because
|
||||
// we want to avoid doing a complete rerender of the recent topics view,
|
||||
// because that can be expensive.
|
||||
const current_muted_topics = user_topics.get_user_topics_for_visibility_policy(
|
||||
user_topics.all_visibility_policies.MUTED,
|
||||
recent_topics_ui.update_topic_visibility_policy(
|
||||
user_topic_event.stream_id,
|
||||
user_topic_event.topic_name,
|
||||
);
|
||||
const maybe_affected_topics = _.unionWith(old_muted_topics, current_muted_topics, _.isEqual);
|
||||
|
||||
for (const topic_data of maybe_affected_topics) {
|
||||
recent_topics_ui.update_topic_is_muted(topic_data.stream_id, topic_data.topic);
|
||||
}
|
||||
}
|
||||
|
||||
export function handle_topic_updates(user_topic) {
|
||||
const old_muted_topics = user_topics.get_user_topics_for_visibility_policy(
|
||||
user_topics.all_visibility_policies.MUTED,
|
||||
);
|
||||
user_topics.set_user_topic(user_topic);
|
||||
popover_menus.get_topic_menu_popover()?.hide();
|
||||
unread_ui.update_unread_counts();
|
||||
rerender_for_muted_topic(old_muted_topics);
|
||||
}
|
||||
|
||||
export function toggle_topic_visibility_policy(message) {
|
||||
|
||||
@ -618,7 +618,7 @@ export function inplace_rerender(topic_key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function update_topic_is_muted(stream_id, topic) {
|
||||
export function update_topic_visibility_policy(stream_id, topic) {
|
||||
const key = get_topic_key(stream_id, topic);
|
||||
if (!topics.has(key)) {
|
||||
// we receive mute request for a topic we are
|
||||
|
||||
@ -919,13 +919,13 @@ test("basic assertions", ({mock_template, override_rewire}) => {
|
||||
"1:topic-7,1:topic-3,4:topic-10,1:topic-6,1:topic-5,1:topic-4,1:topic-2,1:topic-1,6,7,8",
|
||||
);
|
||||
|
||||
// update_topic_is_muted now relies on external libraries completely
|
||||
// update_topic_visibility_policy now relies on external libraries completely
|
||||
// so we don't need to check anythere here.
|
||||
generate_topic_data([[1, topic1, 0, false]]);
|
||||
$(".home-page-input").trigger("focus");
|
||||
assert.equal(rt.update_topic_is_muted(stream1, topic1), true);
|
||||
assert.equal(rt.update_topic_visibility_policy(stream1, topic1), true);
|
||||
// a topic gets muted which we are not tracking
|
||||
assert.equal(rt.update_topic_is_muted(stream1, "topic-10"), false);
|
||||
assert.equal(rt.update_topic_visibility_policy(stream1, "topic-10"), false);
|
||||
});
|
||||
|
||||
test("test_reify_local_echo_message", ({mock_template}) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user