2023-06-16 13:45:41 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2023-06-16 13:45:41 +02:00
|
|
|
import * as overlays from "./overlays";
|
2023-04-01 20:49:16 +02:00
|
|
|
import * as popover_menus from "./popover_menus";
|
2021-06-10 14:18:46 +02:00
|
|
|
import * as recent_topics_ui from "./recent_topics_ui";
|
2023-06-16 13:45:41 +02:00
|
|
|
import * as settings_user_topics from "./settings_user_topics";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_list from "./stream_list";
|
2023-04-15 17:59:26 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-02-28 00:41:32 +01:00
|
|
|
import * as unread_ui from "./unread_ui";
|
2022-08-14 15:33:13 +02:00
|
|
|
import * as user_topics from "./user_topics";
|
2021-02-10 16:47:06 +01:00
|
|
|
|
2023-04-22 01:28:00 +02:00
|
|
|
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();
|
|
|
|
|
2013-09-30 22:03:10 +02:00
|
|
|
stream_list.update_streams_sidebar();
|
2023-04-22 01:28:00 +02:00
|
|
|
unread_ui.update_unread_counts();
|
message lists: Don't allow user/topic mute message filtering independently.
This basically reverts 4bd7ec7c3699b08655fb3d6ae2a00a19c8a086db and
3a9dfc02e6414089de8ed5cbc85eb69f60454013.
The plan earlier was to have compeletely different codepaths
for user and topic muting, so that we could call seperate
functions in the message list class on receiving the respective
events.
However, this cannot be done, because if we, for example, on
receiving a `muted_users` event, filter `_all_items` based on
just user mutes, and store the result in `_items`, then, that
result may still contain topic-muted messages, which is
undesirable. Hence whenever we filter messages, we must do so
based on both user as well as topic muting.
(The code for the former will be added in further commits.)
So, we will have a single function which will handle updating
the message lists for muting.
2021-05-07 22:13:03 +02:00
|
|
|
message_lists.current.update_muting_and_rerender();
|
2021-03-30 02:21:21 +02:00
|
|
|
if (message_lists.current !== message_lists.home) {
|
message lists: Don't allow user/topic mute message filtering independently.
This basically reverts 4bd7ec7c3699b08655fb3d6ae2a00a19c8a086db and
3a9dfc02e6414089de8ed5cbc85eb69f60454013.
The plan earlier was to have compeletely different codepaths
for user and topic muting, so that we could call seperate
functions in the message list class on receiving the respective
events.
However, this cannot be done, because if we, for example, on
receiving a `muted_users` event, filter `_all_items` based on
just user mutes, and store the result in `_items`, then, that
result may still contain topic-muted messages, which is
undesirable. Hence whenever we filter messages, we must do so
based on both user as well as topic muting.
(The code for the former will be added in further commits.)
So, we will have a single function which will handle updating
the message lists for muting.
2021-05-07 22:13:03 +02:00
|
|
|
message_lists.home.update_muting_and_rerender();
|
2013-09-27 16:26:04 +02:00
|
|
|
}
|
2023-04-22 01:28:00 +02:00
|
|
|
recent_topics_ui.update_topic_visibility_policy(
|
|
|
|
user_topic_event.stream_id,
|
|
|
|
user_topic_event.topic_name,
|
2023-04-12 11:01:25 +02:00
|
|
|
);
|
2023-06-16 13:45:41 +02:00
|
|
|
|
|
|
|
if (overlays.settings_open() && settings_user_topics.loaded) {
|
|
|
|
const stream_id = user_topic_event.stream_id;
|
|
|
|
const topic_name = user_topic_event.topic_name;
|
|
|
|
const visibility_policy = user_topic_event.visibility_policy;
|
|
|
|
|
|
|
|
// Find the row with the specified stream_id and topic_name
|
|
|
|
const $row = $('tr[data-stream-id="' + stream_id + '"][data-topic="' + topic_name + '"]');
|
|
|
|
|
|
|
|
if ($row.length) {
|
|
|
|
// If the row exists, update the status only.
|
|
|
|
// We don't call 'populate_list' in this case as it re-creates the panel (re-sorts by date updated +
|
|
|
|
// removes topics with status set to 'Default for stream'), making it hard to review the changes
|
|
|
|
// and undo if needed.
|
|
|
|
const $status = $row.find("select.settings_user_topic_visibility_policy");
|
|
|
|
$status.val(visibility_policy);
|
|
|
|
} else {
|
|
|
|
// If the row doesn't exist, the user must have set the visibility policy
|
|
|
|
// via another tab. We call 'populate_list' to re-create the panel, hence
|
|
|
|
// including the new row.
|
|
|
|
settings_user_topics.populate_list();
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 17:15:51 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 17:59:26 +02:00
|
|
|
export function toggle_topic_visibility_policy(message) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = message.stream_id;
|
2020-02-19 00:04:12 +01:00
|
|
|
const topic = message.topic;
|
2018-12-22 19:18:59 +01:00
|
|
|
|
2023-04-15 17:59:26 +02:00
|
|
|
if (
|
|
|
|
user_topics.is_topic_muted(stream_id, topic) ||
|
|
|
|
user_topics.is_topic_unmuted(stream_id, topic)
|
|
|
|
) {
|
2023-04-11 07:34:13 +02:00
|
|
|
user_topics.set_user_topic_visibility_policy(
|
|
|
|
stream_id,
|
|
|
|
topic,
|
|
|
|
user_topics.all_visibility_policies.INHERIT,
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (message.type === "stream") {
|
2023-04-15 17:59:26 +02:00
|
|
|
if (sub_store.get(stream_id).is_muted) {
|
|
|
|
user_topics.set_user_topic_visibility_policy(
|
|
|
|
stream_id,
|
|
|
|
topic,
|
|
|
|
user_topics.all_visibility_policies.UNMUTED,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
user_topics.set_user_topic_visibility_policy(
|
|
|
|
stream_id,
|
|
|
|
topic,
|
|
|
|
user_topics.all_visibility_policies.MUTED,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
2017-03-24 23:25:04 +01:00
|
|
|
}
|
2021-02-28 00:41:32 +01:00
|
|
|
}
|