2021-04-17 17:15:51 +02:00
|
|
|
import _ from "lodash";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2021-02-28 00:41:32 +01:00
|
|
|
import render_topic_muted from "../templates/topic_muted.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 00:41:32 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as feedback_widget from "./feedback_widget";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t} from "./i18n";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-06-10 14:18:46 +02:00
|
|
|
import * as recent_topics_ui from "./recent_topics_ui";
|
2021-03-27 11:39:36 +01:00
|
|
|
import * as settings_muted_topics from "./settings_muted_topics";
|
2021-02-28 00:53:59 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_list from "./stream_list";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as stream_popover from "./stream_popover";
|
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
|
|
|
|
2021-04-17 17:15:51 +02:00
|
|
|
export function rerender_for_muted_topic(old_muted_topics) {
|
2013-09-30 22:03:10 +02:00
|
|
|
stream_list.update_streams_sidebar();
|
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
|
|
|
}
|
2021-03-27 11:39:36 +01:00
|
|
|
if (overlays.settings_open() && settings_muted_topics.loaded) {
|
2021-04-27 12:09:08 +02:00
|
|
|
settings_muted_topics.populate_list();
|
2020-07-12 00:13:47 +02:00
|
|
|
}
|
2021-04-17 17:15:51 +02:00
|
|
|
|
|
|
|
// 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.
|
2022-08-14 15:33:13 +02:00
|
|
|
const current_muted_topics = user_topics.get_muted_topics();
|
2021-04-17 17:15:51 +02:00
|
|
|
const maybe_affected_topics = _.unionWith(old_muted_topics, current_muted_topics, _.isEqual);
|
|
|
|
|
|
|
|
for (const topic_data of maybe_affected_topics) {
|
2021-06-10 14:18:46 +02:00
|
|
|
recent_topics_ui.update_topic_is_muted(topic_data.stream_id, topic_data.topic);
|
2021-04-17 17:15:51 +02:00
|
|
|
}
|
2021-02-28 00:41:32 +01:00
|
|
|
}
|
2013-09-27 16:26:04 +02:00
|
|
|
|
2022-08-26 22:59:07 +02:00
|
|
|
export function handle_topic_updates(user_topic) {
|
2022-08-14 15:33:13 +02:00
|
|
|
const old_muted_topics = user_topics.get_muted_topics();
|
2022-08-26 22:59:07 +02:00
|
|
|
user_topics.set_user_topic(user_topic);
|
2021-04-17 17:15:51 +02:00
|
|
|
stream_popover.hide_topic_popover();
|
|
|
|
unread_ui.update_unread_counts();
|
|
|
|
rerender_for_muted_topic(old_muted_topics);
|
|
|
|
}
|
|
|
|
|
2021-04-30 08:59:55 +02:00
|
|
|
export function mute_topic(stream_id, topic, from_hotkey) {
|
2021-04-17 17:15:51 +02:00
|
|
|
const stream_name = stream_data.maybe_get_stream_name(stream_id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2021-04-17 17:15:51 +02:00
|
|
|
topic,
|
2020-07-15 01:29:15 +02:00
|
|
|
op: "add",
|
2013-09-10 20:07:24 +02:00
|
|
|
};
|
2021-04-17 17:15:51 +02:00
|
|
|
|
2017-08-29 21:40:38 +02:00
|
|
|
channel.patch({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/subscriptions/muted_topics",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2021-04-17 17:15:51 +02:00
|
|
|
success() {
|
2021-04-30 08:59:55 +02:00
|
|
|
if (!from_hotkey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following feedback_widget notice helps avoid
|
|
|
|
// confusion when a user who is not familiar with Zulip's
|
|
|
|
// keyboard UI hits "M" in the wrong context and has a
|
|
|
|
// bunch of messages suddenly disappear. This notice is
|
|
|
|
// only useful when muting from the keyboard, since you
|
|
|
|
// know what you did if you triggered muting with the
|
|
|
|
// mouse.
|
2021-04-17 17:15:51 +02:00
|
|
|
feedback_widget.show({
|
2022-01-25 11:36:19 +01:00
|
|
|
populate($container) {
|
2021-04-17 17:15:51 +02:00
|
|
|
const rendered_html = render_topic_muted();
|
2022-01-25 11:36:19 +01:00
|
|
|
$container.html(rendered_html);
|
|
|
|
$container.find(".stream").text(stream_name);
|
|
|
|
$container.find(".topic").text(topic);
|
2021-04-17 17:15:51 +02:00
|
|
|
},
|
|
|
|
on_undo() {
|
|
|
|
unmute_topic(stream_id, topic);
|
|
|
|
},
|
|
|
|
title_text: $t({defaultMessage: "Topic muted"}),
|
|
|
|
undo_button_text: $t({defaultMessage: "Unmute"}),
|
|
|
|
});
|
|
|
|
},
|
2017-08-29 21:40:38 +02:00
|
|
|
});
|
2021-02-28 00:41:32 +01:00
|
|
|
}
|
2017-08-29 21:40:38 +02:00
|
|
|
|
2021-04-17 17:15:51 +02:00
|
|
|
export function unmute_topic(stream_id, topic) {
|
|
|
|
// Accidentally unmuting a topic isn't as much an issue as accidentally muting
|
|
|
|
// a topic, so we don't show a popup after unmuting.
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2021-04-17 17:15:51 +02:00
|
|
|
topic,
|
2020-07-15 01:29:15 +02:00
|
|
|
op: "remove",
|
2017-08-29 21:40:38 +02:00
|
|
|
};
|
2021-04-17 17:15:51 +02:00
|
|
|
|
2017-08-29 21:40:38 +02:00
|
|
|
channel.patch({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/subscriptions/muted_topics",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2021-04-17 17:15:51 +02:00
|
|
|
success() {
|
|
|
|
feedback_widget.dismiss();
|
2018-12-20 18:04:46 +01:00
|
|
|
},
|
|
|
|
});
|
2021-02-28 00:41:32 +01:00
|
|
|
}
|
2017-03-23 06:57:36 +01:00
|
|
|
|
2021-02-28 00:41:32 +01:00
|
|
|
export function toggle_topic_mute(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
|
|
|
|
2022-08-14 15:33:13 +02:00
|
|
|
if (user_topics.is_topic_muted(stream_id, topic)) {
|
2021-02-28 00:41:32 +01:00
|
|
|
unmute_topic(stream_id, topic);
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (message.type === "stream") {
|
2021-04-30 08:59:55 +02:00
|
|
|
mute_topic(stream_id, topic, true);
|
2017-03-24 23:25:04 +01:00
|
|
|
}
|
2021-02-28 00:41:32 +01:00
|
|
|
}
|