2021-03-30 06:23:09 +02:00
|
|
|
import {all_messages_data} from "./all_messages_data";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-28 00:59:17 +01:00
|
|
|
import * as message_scroll from "./message_scroll";
|
2021-02-28 01:10:31 +01:00
|
|
|
import * as message_util from "./message_util";
|
2021-02-28 00:54:52 +01:00
|
|
|
import * as message_viewport from "./message_viewport";
|
2021-02-28 01:05:26 +01:00
|
|
|
import * as navigate from "./navigate";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-11-20 11:51:35 +01:00
|
|
|
import * as settings_notifications from "./settings_notifications";
|
2022-03-03 23:10:01 +01:00
|
|
|
import * as stream_edit from "./stream_edit";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_list from "./stream_list";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 00:54:52 +01:00
|
|
|
export function update_is_muted(sub, value) {
|
2019-05-21 10:41:53 +02:00
|
|
|
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
|
2022-04-04 06:09:04 +02:00
|
|
|
if (overlays.is_active() || overlays.is_modal_open()) {
|
2017-03-19 16:00:35 +01:00
|
|
|
saved_ypos = message_viewport.scrollTop();
|
2020-07-15 00:34:28 +02:00
|
|
|
} else if (
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.home === message_lists.current &&
|
|
|
|
message_lists.current.selected_row().offset() !== null
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2021-03-30 02:21:21 +02:00
|
|
|
msg_offset = message_lists.current.selected_row().offset().top;
|
2017-03-19 16:00:35 +01:00
|
|
|
}
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.home.clear({clear_selected_id: false});
|
2017-03-19 16:00:35 +01:00
|
|
|
|
2021-03-30 06:23:09 +02:00
|
|
|
// Recreate the message_lists.home with the newly filtered all_messages_data
|
|
|
|
message_util.add_old_messages(all_messages_data.all_messages(), message_lists.home);
|
2017-03-19 16:00:35 +01:00
|
|
|
|
|
|
|
// Ensure we're still at the same scroll position
|
2022-04-04 06:09:04 +02:00
|
|
|
if (overlays.is_overlay_or_modal_open()) {
|
2017-03-19 16:00:35 +01:00
|
|
|
message_viewport.scrollTop(saved_ypos);
|
2021-03-30 02:21:21 +02:00
|
|
|
} else if (message_lists.home === message_lists.current) {
|
2017-03-19 16:00:35 +01:00
|
|
|
// We pass use_closest to handle the case where the
|
|
|
|
// currently selected message is being hidden from the
|
|
|
|
// home view
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.home.select_id(message_lists.home.selected_id(), {
|
2020-07-15 00:34:28 +02:00
|
|
|
use_closest: true,
|
|
|
|
empty_ok: true,
|
|
|
|
});
|
2021-03-30 02:21:21 +02:00
|
|
|
if (message_lists.current.selected_id() !== -1) {
|
|
|
|
message_lists.current.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
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
if (!message_lists.home.empty()) {
|
|
|
|
message_util.do_unread_count_updates(message_lists.home.all_messages());
|
2017-03-19 16:00:35 +01:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
|
2021-11-20 11:51:35 +01:00
|
|
|
settings_notifications.update_muted_stream_state(sub);
|
2022-03-03 23:10:01 +01:00
|
|
|
stream_edit.update_muting_rendering(sub);
|
2019-05-15 08:54:25 +02:00
|
|
|
stream_list.set_in_home_view(sub.stream_id, !sub.is_muted);
|
2021-02-28 00:54:52 +01:00
|
|
|
}
|