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.

sub_store: Update first_message_id of stream if we can.

Aman Agrawal15195fc08f0c
diff --git a/web/src/stream_topic_history.ts b/web/src/stream_topic_history.ts
index 17c4e9220cf..328a8ee36d4 100644
--- a/web/src/stream_topic_history.ts
+++ b/web/src/stream_topic_history.ts
@@ -126,17 +126,42 @@ export class PerStreamHistory {
return this.topics.size !== 0;
}
- update_stream_max_message_id(message_id: number): void {
+ update_stream_with_message_id(message_id: number): void {
if (message_id > this.max_message_id) {
this.max_message_id = message_id;
}
+
+ // Update the first_message_id for the stream.
+ // It is fine if `first_message_id` changes to be higher
+ // due to removal of messages since it will not cause to
+ // display wrong list of topics. So, we don't update it here.
+ // On the other hand, if it changes to be lower
+ // we may miss some topics in autocomplete in the range
+ // of outdated-`first_message_id` to new-`message_id`.
+ // Note that this can only happen if a user moves old
+ // messages to the stream from another stream.
+ const sub = sub_store.get(this.stream_id);
+ if (!sub) {
+ return;
+ }
+
+ if (sub.first_message_id === null || sub.first_message_id === undefined) {
+ fetched_stream_ids.delete(this.stream_id);
+ sub.first_message_id = message_id;
+ return;
+ }
+
+ if (sub.first_message_id > message_id) {
+ fetched_stream_ids.delete(this.stream_id);
+ sub.first_message_id = message_id;
+ }
}
add_or_update(topic_name: string, message_id: number): void {
// The `message_id` provided here can easily be far from the latest
// message in the topic, but it is more important for us to cache the topic
// for autocomplete purposes than to have an accurate max message ID.
- this.update_stream_max_message_id(message_id);
+ this.update_stream_with_message_id(message_id);
const existing = this.topics.get(topic_name);
@@ -203,7 +228,7 @@ export class PerStreamHistory {
pretty_name: topic_name,
count: 0,
});
- this.update_stream_max_message_id(message_id);
+ this.update_stream_with_message_id(message_id);
}
}