recent view: Import module instead of separate functions.

This commit is contained in:
evykassirer 2023-10-29 18:46:18 -07:00 committed by Tim Abbott
parent 803b7b4b93
commit f786b10403
1 changed files with 24 additions and 23 deletions

View File

@ -25,8 +25,8 @@ import {page_params} from "./page_params";
import * as people from "./people";
import * as popovers from "./popovers";
import * as recent_senders from "./recent_senders";
import {get, process_message, topics} from "./recent_view_data";
import {get_key_from_message, get_topic_key, is_visible, set_visible} from "./recent_view_util";
import * as recent_view_data from "./recent_view_data";
import * as recent_view_util from "./recent_view_util";
import * as scroll_util from "./scroll_util";
import * as sidebar_ui from "./sidebar_ui";
import * as stream_data from "./stream_data";
@ -89,7 +89,7 @@ const recent_conversation_key_prefix = "recent_conversation:";
export function clear_for_tests() {
filters.clear();
topics.clear();
recent_view_data.topics.clear();
topics_widget = undefined;
}
@ -100,7 +100,7 @@ export function save_filters() {
export function is_in_focus() {
// Check if user is focused on Recent Conversations.
return (
is_visible() &&
recent_view_util.is_visible() &&
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
@ -313,7 +313,7 @@ export function get_focused_row_message() {
const $topic_rows = $("#recent_view_table table tbody tr");
const $topic_row = $topic_rows.eq(row_focus);
const conversation_id = $topic_row.attr("id").slice(recent_conversation_key_prefix.length);
const topic_last_msg_id = topics.get(conversation_id).last_msg_id;
const topic_last_msg_id = recent_view_data.topics.get(conversation_id).last_msg_id;
return message_store.get(topic_last_msg_id);
}
return undefined;
@ -339,8 +339,9 @@ export function revive_current_focus() {
if (last_visited_topic) {
// If the only message in the topic was deleted,
// then the topic will not be in Recent Conversations data.
if (topics.get(last_visited_topic) !== undefined) {
const topic_last_msg_id = topics.get(last_visited_topic).last_msg_id;
if (recent_view_data.topics.get(last_visited_topic) !== undefined) {
const topic_last_msg_id =
recent_view_data.topics.get(last_visited_topic).last_msg_id;
const current_list = topics_widget.get_current_list();
const last_visited_topic_index = current_list.findIndex(
(topic) => topic.last_msg_id === topic_last_msg_id,
@ -392,7 +393,7 @@ export function process_messages(messages, msg_list_data) {
let conversation_data_updated = false;
if (messages.length > 0) {
for (const msg of messages) {
if (process_message(msg)) {
if (recent_view_data.process_message(msg)) {
conversation_data_updated = true;
}
}
@ -460,7 +461,7 @@ function format_conversation(conversation_data) {
const time = new Date(last_msg.timestamp * 1000);
const type = last_msg.type;
context.full_last_msg_date_time = timerender.get_full_datetime_clarification(time);
context.conversation_key = get_key_from_message(last_msg);
context.conversation_key = recent_view_util.get_key_from_message(last_msg);
context.unread_count = message_to_conversation_unread_count(last_msg);
context.last_msg_time = timerender.relative_time_string_from_date({
date: time,
@ -592,14 +593,14 @@ function format_conversation(conversation_data) {
function get_topic_row(topic_data) {
const msg = message_store.get(topic_data.last_msg_id);
const topic_key = get_key_from_message(msg);
const topic_key = recent_view_util.get_key_from_message(msg);
return $(`#${CSS.escape(recent_conversation_key_prefix + topic_key)}`);
}
export function process_topic_edit(old_stream_id, old_topic, new_topic, new_stream_id) {
// See `recent_senders.process_topic_edit` for
// logic behind this and important notes on use of this function.
topics.delete(get_topic_key(old_stream_id, old_topic));
recent_view_data.topics.delete(recent_view_util.get_topic_key(old_stream_id, old_topic));
const old_topic_msgs = message_util.get_messages_in_topic(old_stream_id, old_topic);
process_messages(old_topic_msgs);
@ -622,7 +623,7 @@ export function update_topics_of_deleted_message_ids(message_ids) {
const topics_to_rerender = message_util.get_topics_for_message_ids(message_ids);
for (const [stream_id, topic] of topics_to_rerender.values()) {
topics.delete(get_topic_key(stream_id, topic));
recent_view_data.topics.delete(recent_view_util.get_topic_key(stream_id, topic));
const msgs = message_util.get_messages_in_topic(stream_id, topic);
process_messages(msgs);
}
@ -683,14 +684,14 @@ export function filters_should_hide_topic(topic_data) {
}
export function inplace_rerender(topic_key) {
if (!is_visible()) {
if (!recent_view_util.is_visible()) {
return false;
}
if (!topics.has(topic_key)) {
if (!recent_view_data.topics.has(topic_key)) {
return false;
}
const topic_data = topics.get(topic_key);
const topic_data = recent_view_data.topics.get(topic_key);
const $topic_row = get_topic_row(topic_data);
// We cannot rely on `topic_widget.meta.filtered_list` to know
// if a topic is rendered since the `filtered_list` might have
@ -735,8 +736,8 @@ export function inplace_rerender(topic_key) {
}
export function update_topic_visibility_policy(stream_id, topic) {
const key = get_topic_key(stream_id, topic);
if (!topics.has(key)) {
const key = recent_view_util.get_topic_key(stream_id, topic);
if (!recent_view_data.topics.has(key)) {
// we receive mute request for a topic we are
// not tracking currently
return false;
@ -747,7 +748,7 @@ export function update_topic_visibility_policy(stream_id, topic) {
}
export function update_topic_unread_count(message) {
const topic_key = get_key_from_message(message);
const topic_key = recent_view_util.get_key_from_message(message);
inplace_rerender(topic_key);
}
@ -935,12 +936,12 @@ function is_scroll_position_for_render(scroll_container) {
}
export function complete_rerender() {
if (!is_visible()) {
if (!recent_view_util.is_visible()) {
return;
}
// Show topics list
const mapped_topic_values = [...get().values()];
const mapped_topic_values = [...recent_view_data.get().values()];
if (topics_widget) {
topics_widget.replace_list_data(mapped_topic_values);
@ -1012,8 +1013,8 @@ export function show() {
// function. So, we reuse it here.
update_compose: compose_closed_ui.update_buttons_for_non_stream_views,
is_recent_view: true,
is_visible,
set_visible,
is_visible: recent_view_util.is_visible,
set_visible: recent_view_util.set_visible,
complete_rerender,
});
}
@ -1025,7 +1026,7 @@ function filter_buttons() {
export function hide() {
views_util.hide({
$view: $("#recent_view"),
set_visible,
set_visible: recent_view_util.set_visible,
});
}