2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-04-17 17:15:51 +02:00
|
|
|
import _ from "lodash";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2021-06-21 09:59:51 +02:00
|
|
|
import render_confirm_mute_user from "../templates/confirm_dialog/confirm_mute_user.hbs";
|
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-04-23 17:30:00 +02:00
|
|
|
import * as activity from "./activity";
|
2021-02-28 00:41:32 +01:00
|
|
|
import * as channel from "./channel";
|
2021-03-27 13:14:34 +01:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-02-28 00:41:32 +01:00
|
|
|
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-06-28 20:39:04 +02:00
|
|
|
import * as muted_topics from "./muted_topics";
|
2021-06-27 21:38:26 +02:00
|
|
|
import * as muted_users from "./muted_users";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-27 13:14:34 +01:00
|
|
|
import * as people from "./people";
|
2021-04-29 14:11:55 +02:00
|
|
|
import * as pm_list from "./pm_list";
|
2021-03-27 13:14:34 +01:00
|
|
|
import * as popovers from "./popovers";
|
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-04-17 07:22:25 +02:00
|
|
|
import * as settings_muted_users from "./settings_muted_users";
|
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";
|
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.
|
2021-06-28 20:39:04 +02:00
|
|
|
const current_muted_topics = muted_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
|
|
|
|
2021-07-01 09:30:47 +02:00
|
|
|
export function handle_topic_updates(muted_topics_list) {
|
2021-06-28 20:39:04 +02:00
|
|
|
const old_muted_topics = muted_topics.get_muted_topics();
|
2021-07-01 09:30:47 +02:00
|
|
|
muted_topics.set_muted_topics(muted_topics_list);
|
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",
|
2017-08-29 21:40:38 +02:00
|
|
|
idempotent: true,
|
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({
|
|
|
|
populate(container) {
|
|
|
|
const rendered_html = render_topic_muted();
|
|
|
|
container.html(rendered_html);
|
|
|
|
container.find(".stream").text(stream_name);
|
|
|
|
container.find(".topic").text(topic);
|
|
|
|
},
|
|
|
|
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",
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
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
|
|
|
|
2021-06-28 20:39:04 +02:00
|
|
|
if (muted_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
|
|
|
}
|
2021-03-27 12:42:16 +01:00
|
|
|
|
2021-03-27 13:14:34 +01:00
|
|
|
export function mute_user(user_id) {
|
|
|
|
channel.post({
|
|
|
|
url: "/json/users/me/muted_users/" + user_id,
|
|
|
|
idempotent: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function confirm_mute_user(user_id) {
|
|
|
|
function on_click() {
|
|
|
|
mute_user(user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const modal_parent = $(".mute-user-modal-holder");
|
|
|
|
const html_body = render_confirm_mute_user({
|
|
|
|
user_name: people.get_full_name(user_id),
|
|
|
|
});
|
|
|
|
|
|
|
|
confirm_dialog.launch({
|
|
|
|
parent: modal_parent,
|
|
|
|
html_heading: $t({defaultMessage: "Mute user"}),
|
2021-05-08 15:51:20 +02:00
|
|
|
help_link: "/help/mute-a-user",
|
2021-03-27 13:14:34 +01:00
|
|
|
html_body,
|
2021-07-05 15:11:23 +02:00
|
|
|
html_submit_button: $t({defaultMessage: "Confirm"}),
|
2021-03-27 13:14:34 +01:00
|
|
|
on_click,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unmute_user(user_id) {
|
|
|
|
channel.del({
|
|
|
|
url: "/json/users/me/muted_users/" + user_id,
|
|
|
|
idempotent: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-17 07:22:25 +02:00
|
|
|
export function rerender_for_muted_user() {
|
2021-05-07 22:34:38 +02:00
|
|
|
message_lists.current.update_muting_and_rerender();
|
message view: Hide messages sent by muted users.
* We hide the sender and reactions on messages sent by muted
users, and replace the content with a "This message was hidden"
dialog.
* Ideally, we should collapse a series of consequetive
messages sent by muted users into one such dialog, but
that could break the cursor behaviour and `near/<message_id`
links, so we as of now show one dialog per muted message.
* Because we hide the sender, there is a chance of the first
hidden message in a group looking like it was sent by the
author of the message above it. To tackle this, we intentionally
make the hidden message dialog float-left, so that it is clear
that this is a special type of message.
* For context, we still show the timestamp of the message.
* Starring, editing, deleting etc a message still work just like
before.
A further commit will add the ability to reveal a
hidden message.
2021-05-04 09:01:47 +02:00
|
|
|
if (message_lists.current !== message_lists.home) {
|
2021-05-07 22:34:38 +02:00
|
|
|
message_lists.home.update_muting_and_rerender();
|
message view: Hide messages sent by muted users.
* We hide the sender and reactions on messages sent by muted
users, and replace the content with a "This message was hidden"
dialog.
* Ideally, we should collapse a series of consequetive
messages sent by muted users into one such dialog, but
that could break the cursor behaviour and `near/<message_id`
links, so we as of now show one dialog per muted message.
* Because we hide the sender, there is a chance of the first
hidden message in a group looking like it was sent by the
author of the message above it. To tackle this, we intentionally
make the hidden message dialog float-left, so that it is clear
that this is a special type of message.
* For context, we still show the timestamp of the message.
* Starring, editing, deleting etc a message still work just like
before.
A further commit will add the ability to reveal a
hidden message.
2021-05-04 09:01:47 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 07:22:25 +02:00
|
|
|
if (overlays.settings_open() && settings_muted_users.loaded) {
|
|
|
|
settings_muted_users.populate_list();
|
|
|
|
}
|
2021-04-23 17:30:00 +02:00
|
|
|
|
|
|
|
activity.redraw();
|
2021-04-29 14:11:55 +02:00
|
|
|
pm_list.update_private_messages();
|
2021-05-12 08:13:26 +02:00
|
|
|
|
|
|
|
// If a user is (un)muted, we want to update their avatars on the recent topics
|
|
|
|
// participants column.
|
2021-06-10 14:18:46 +02:00
|
|
|
recent_topics_ui.complete_rerender();
|
2021-04-17 07:22:25 +02:00
|
|
|
}
|
|
|
|
|
2021-03-27 12:42:16 +01:00
|
|
|
export function handle_user_updates(muted_user_ids) {
|
2021-03-27 13:14:34 +01:00
|
|
|
popovers.hide_all();
|
2021-06-27 21:38:26 +02:00
|
|
|
muted_users.set_muted_users(muted_user_ids);
|
2021-04-17 07:22:25 +02:00
|
|
|
rerender_for_muted_user();
|
2021-03-27 12:42:16 +01:00
|
|
|
}
|