Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

recent-conversations: Check for data change when processing message.

Lauryn Menarda67a622adce3
diff --git a/static/js/recent_topics_data.js b/static/js/recent_topics_data.js
index ccc21a192ce..6a413bf3006 100644
--- a/static/js/recent_topics_data.js
+++ b/static/js/recent_topics_data.js
@@ -1,12 +1,15 @@
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 const topics = new Map();
+// For stream messages, key is stream-id:topic.
+// For pms, key is the user IDs to whom the message is being sent.
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.
+ // Return whether any conversation data is updated.
+ let conversation_data_updated = false;
+
+ // Initialize conversation data
const key = get_key_from_message(msg);
if (!topics.has(key)) {
topics.set(key, {
@@ -14,9 +17,9 @@ export function process_message(msg) {
participated: false,
type: msg.type,
});
+ conversation_data_updated = true;
}
- // Update topic data
- const is_ours = people.is_my_user_id(msg.sender_id);
+ // Update conversation data
const topic_data = topics.get(key);
if (topic_data.last_msg_id < msg.id) {
// NOTE: This also stores locally echoed msg_id which
@@ -24,13 +27,18 @@ export function process_message(msg) {
// We store it now and reify it when response is available
// from server.
topic_data.last_msg_id = msg.id;
+ conversation_data_updated = true;
}
// 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;
+ if (!topic_data.participated && people.is_my_user_id(msg.sender_id)) {
+ topic_data.participated = true;
+ conversation_data_updated = true;
+ }
+ return conversation_data_updated;
}
function get_sorted_topics() {
diff --git a/static/js/recent_topics_ui.js b/static/js/recent_topics_ui.js
index 239ec31a3d4..3fd67ff37a4 100644
--- a/static/js/recent_topics_ui.js
+++ b/static/js/recent_topics_ui.js
@@ -298,10 +298,17 @@ export function process_messages(messages) {
// the UX can be bad if user wants to scroll down the list as
// the UI will be returned to the beginning of the list on every
// update.
+ let conversation_data_updated = false;
if (messages.length > 0) {
for (const msg of messages) {
- process_message(msg);
+ if (process_message(msg)) {
+ conversation_data_updated = true;
+ }
}
+ }
+
+ // Only rerender if conversation data actually changed.
+ if (conversation_data_updated) {
complete_rerender();
}
}