2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-05-21 10:41:53 +02:00
|
|
|
exports.update_is_muted = function (sub, value) {
|
|
|
|
sub.is_muted = value;
|
2017-03-19 16:00:35 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let msg_offset;
|
|
|
|
let saved_ypos;
|
2017-03-19 16:00:35 +01:00
|
|
|
// Save our current scroll position
|
2017-05-27 15:40:54 +02:00
|
|
|
if (overlays.is_active()) {
|
2017-03-19 16:00:35 +01:00
|
|
|
saved_ypos = message_viewport.scrollTop();
|
2020-07-15 00:34:28 +02:00
|
|
|
} else if (
|
|
|
|
home_msg_list === current_msg_list &&
|
|
|
|
current_msg_list.selected_row().offset() !== null
|
|
|
|
) {
|
2017-03-19 16:00:35 +01:00
|
|
|
msg_offset = current_msg_list.selected_row().offset().top;
|
|
|
|
}
|
|
|
|
|
|
|
|
home_msg_list.clear({clear_selected_id: false});
|
|
|
|
|
|
|
|
// Recreate the home_msg_list with the newly filtered message_list.all
|
2019-01-08 01:26:02 +01:00
|
|
|
message_util.add_old_messages(message_list.all.all_messages(), home_msg_list);
|
2017-03-19 16:00:35 +01:00
|
|
|
|
|
|
|
// Ensure we're still at the same scroll position
|
2017-05-27 15:40:54 +02:00
|
|
|
if (overlays.is_active()) {
|
2017-03-19 16:00:35 +01:00
|
|
|
message_viewport.scrollTop(saved_ypos);
|
|
|
|
} else if (home_msg_list === current_msg_list) {
|
|
|
|
// We pass use_closest to handle the case where the
|
|
|
|
// currently selected message is being hidden from the
|
|
|
|
// home view
|
2020-07-15 00:34:28 +02:00
|
|
|
home_msg_list.select_id(home_msg_list.selected_id(), {
|
|
|
|
use_closest: true,
|
|
|
|
empty_ok: true,
|
|
|
|
});
|
2017-03-19 16:00:35 +01:00
|
|
|
if (current_msg_list.selected_id() !== -1) {
|
2018-04-14 01:10:22 +02:00
|
|
|
current_msg_list.view.set_message_offset(msg_offset);
|
2017-03-19 16:00:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:35:18 +02:00
|
|
|
// In case we added messages to what's visible in the home
|
|
|
|
// view, we need to re-scroll to make sure the pointer is
|
|
|
|
// still visible. We don't want the auto-scroll handler to
|
|
|
|
// move our pointer to the old scroll location before we have
|
|
|
|
// a chance to update it.
|
|
|
|
navigate.plan_scroll_to_selected();
|
2020-06-18 08:29:08 +02:00
|
|
|
message_scroll.suppress_selection_update_on_next_scroll();
|
2017-03-19 16:00:35 +01:00
|
|
|
|
2018-06-04 21:09:11 +02:00
|
|
|
if (!home_msg_list.empty()) {
|
2017-03-19 22:43:38 +01:00
|
|
|
message_util.do_unread_count_updates(home_msg_list.all_messages());
|
2017-03-19 16:00:35 +01:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
|
2019-05-15 08:54:25 +02:00
|
|
|
stream_list.set_in_home_view(sub.stream_id, !sub.is_muted);
|
2017-03-19 16:00:35 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const is_muted_checkbox = $(
|
2021-02-03 23:23:32 +01:00
|
|
|
`.subscription_settings[data-stream-id='${CSS.escape(
|
|
|
|
sub.stream_id,
|
|
|
|
)}'] #sub_is_muted_setting .sub_setting_control`,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
is_muted_checkbox.prop("checked", value);
|
2017-03-19 16:00:35 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.stream_muting = exports;
|