mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
As of 550a32b, when private messages were added to recent
conversations, `recent_topics_data.process_message` will
always return true.
Updates `recent_topics_data.process_message` for no return
value. Also, removes the `topic_data_changed` logic from
`recent_topics_ui.process_messages` and instead checks for
messages to process before updating the data and calling the
rerender.
`recent_topics_ui.complete_rerender` first checks for whether
the recent conversations view is visible before rerendering.
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
import * as people from "./people";
|
|
import {get_key_from_message} from "./recent_topics_util";
|
|
|
|
export const topics = new Map(); // Key is stream-id:topic.
|
|
|
|
export function process_message(msg) {
|
|
// Initialize topic and pm data
|
|
// Key for private message is the user id's
|
|
// to whom the message is begin sent.
|
|
const key = get_key_from_message(msg);
|
|
if (!topics.has(key)) {
|
|
topics.set(key, {
|
|
last_msg_id: -1,
|
|
participated: false,
|
|
type: msg.type,
|
|
});
|
|
}
|
|
// Update topic data
|
|
const is_ours = people.is_my_user_id(msg.sender_id);
|
|
const topic_data = topics.get(key);
|
|
if (topic_data.last_msg_id < msg.id) {
|
|
// NOTE: This also stores locally echoed msg_id which
|
|
// has not been successfully received from the server.
|
|
// We store it now and reify it when response is available
|
|
// from server.
|
|
topic_data.last_msg_id = msg.id;
|
|
}
|
|
// TODO: Add backend support for participated topics.
|
|
// Currently participated === recently participated
|
|
// i.e. Only those topics are participated for which we have the user's
|
|
// message fetched in the topic. Ideally we would want this to be attached
|
|
// to topic info fetched from backend, which is currently not a thing.
|
|
topic_data.participated = is_ours || topic_data.participated;
|
|
}
|
|
|
|
function get_sorted_topics() {
|
|
// Sort all recent topics by last message time.
|
|
return new Map(
|
|
Array.from(topics.entries()).sort((a, b) => b[1].last_msg_id - a[1].last_msg_id),
|
|
);
|
|
}
|
|
|
|
export function get() {
|
|
return get_sorted_topics();
|
|
}
|
|
|
|
export function reify_message_id_if_available(opts) {
|
|
// We don't need to reify the message_id of the topic
|
|
// if a new message arrives in the topic from another user,
|
|
// since it replaces the last_msg_id of the topic which
|
|
// we were trying to reify.
|
|
for (const [, value] of topics.entries()) {
|
|
if (value.last_msg_id === opts.old_id) {
|
|
value.last_msg_id = opts.new_id;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|