Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
topics: Topic name case change should be reflected in inbox view.
Shubham Padia1fa967c03430
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.tsindex 63878660d2d..72bae3ad43c 100644--- a/web/src/inbox_ui.ts+++ b/web/src/inbox_ui.ts@@ -421,7 +421,10 @@ export function hide(): void {}function get_topic_key(stream_id: number, topic: string): string {- return stream_id + ":" + topic;+ // Topic names are case-preserving for display, but case insensitive+ // otherwise. We convert the topic key to lowercase to ensure that+ // topic keys with different casing are not treated differently.+ return stream_id + ":" + topic.toLowerCase();}function get_stream_key(stream_id: number): string {diff --git a/web/src/message_events.ts b/web/src/message_events.tsindex 98990c7a5ee..b99a406862d 100644--- a/web/src/message_events.ts+++ b/web/src/message_events.ts@@ -561,6 +561,9 @@ export function update_messages(events: UpdateMessageEvent[]): void {assert(orig_topic !== undefined);assert(new_topic !== undefined);+ // Update Inbox UI to reflect the new case.+ unread.update_unread_topic_name_case(old_stream_id, orig_topic, new_topic);+// Update each message to reflect the new case.for (const message_id of event.message_ids) {const message = message_store.get(message_id);diff --git a/web/src/unread.ts b/web/src/unread.tsindex 7e1c6af534a..9c84420caff 100644--- a/web/src/unread.ts+++ b/web/src/unread.ts@@ -283,6 +283,26 @@ class UnreadTopicCounter {this.reverse_lookup.delete(message_id);}+ update_topic_name_case(stream_id: number, old_topic: string, new_topic: string): void {+ const per_stream_bucketer = this.bucketer.get(stream_id);+ if (per_stream_bucketer === undefined) {+ return;+ }++ const topic_bucket = per_stream_bucketer.get(old_topic);+ if (topic_bucket === undefined) {+ return;+ }++ // Resetting with new_topic updates the display casing for+ // topic_bucket.+ per_stream_bucketer.set(new_topic, topic_bucket);++ for (const message_id of topic_bucket) {+ this.reverse_lookup.set(message_id, {stream_id, topic: new_topic});+ }+ }+get_counts_per_topic(): UnreadTopicCounts {let stream_unread_messages = 0;const topic_counts_by_stream_id = new Map<@@ -729,6 +749,14 @@ export function update_unread_topics(});}+export function update_unread_topic_name_case(+ stream_id: number,+ old_topic: string,+ new_topic: string,+): void {+ unread_topic_counter.update_topic_name_case(stream_id, old_topic, new_topic);+}+export function process_loaded_messages(messages: Message[],expect_no_new_unreads = false,diff --git a/web/tests/unread.test.cjs b/web/tests/unread.test.cjsindex 7bc47b7740a..1af8db153db 100644--- a/web/tests/unread.test.cjs+++ b/web/tests/unread.test.cjs@@ -96,7 +96,7 @@ test("changing_topics", () => {let count = unread.num_unread_for_topic(social.stream_id, "lunch");assert.equal(count, 0);- const stream_id = 100;+ const stream_id = social.stream_id;const wrong_stream_id = 110;const message = {@@ -183,6 +183,11 @@ test("changing_topics", () => {assert.ok(unread.topic_has_any_unread(stream_id, "snack"));assert.ok(!unread.topic_has_any_unread(wrong_stream_id, "snack"));+ unread.update_unread_topic_name_case(stream_id, "snack", "SnaCK");+ const topic_counts = unread.get_unread_topics().topic_counts.get(stream_id);+ assert.ok(topic_counts.has("SnaCK"));+ assert.ok(!topic_counts.has("snack"));+// Test defensive code. Trying to update a message we don't know// about should be a no-op.event = {