Skip to content

Commit 110166e

Browse files
committed
model/views: Acknowledge case sensitive topics in topic list update.
Also, amended related _update_topic_index().
1 parent 3af0aac commit 110166e

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

zulipterminal/model.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ def _fetch_topics_in_streams(self, stream_list: Iterable[int]) -> str:
410410
for stream_id in stream_list:
411411
response = self.client.get_stream_topics(stream_id)
412412
if response['result'] == 'success':
413+
# NOTE: The server only sends the latest topic name version for
414+
# case sensitive topic names.
415+
# See (https://github.com/zulip/zulip/blob
416+
# /2e5f860d41bb441597f7f088a477d5946cab4b13/zerver/lib
417+
# /topic.py#L144).
413418
self.index['topics'][stream_id] = [topic['name'] for
414419
topic in response['topics']]
415420
else:
@@ -931,8 +936,10 @@ def _update_topic_index(self, stream_id: int, topic_name: str) -> None:
931936
"""
932937
topic_list = self.topics_in_stream(stream_id)
933938
for topic_iterator, topic in enumerate(topic_list):
934-
if topic == topic_name:
935-
topic_list.insert(0, topic_list.pop(topic_iterator))
939+
if compare_lowercase(topic, topic_name):
940+
topic_list.pop(topic_iterator)
941+
# Use the latest topic name version to update.
942+
topic_list.insert(0, topic_name)
936943
break
937944
else:
938945
# No previous topics with same topic names are found

zulipterminal/ui_tools/views.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
CHECK_MARK, LIST_TITLE_BAR_LINE, PINNED_STREAMS_DIVIDER,
1313
)
1414
from zulipterminal.helper import (
15-
Message, asynch, canonicalize_topic, match_stream, match_user,
15+
Message, asynch, canonicalize_topic, compare_lowercase, match_stream,
16+
match_user,
1617
)
1718
from zulipterminal.ui_tools.boxes import PanelSearchBox
1819
from zulipterminal.ui_tools.buttons import (
@@ -392,8 +393,20 @@ def update_topics_list(self, stream_id: int, topic_name: str,
392393
# More recent topics are found towards the beginning
393394
# of the list.
394395
for topic_iterator, topic_button in enumerate(self.log):
395-
if topic_button.topic_name == topic_name:
396-
self.log.insert(0, self.log.pop(topic_iterator))
396+
if compare_lowercase(topic_button.topic_name, topic_name):
397+
updated_topic_button = self.log.pop(topic_iterator)
398+
# Use the latest topic name version to update the topic list if
399+
# it has been updated.
400+
if topic_button.topic_name != topic_name:
401+
updated_topic_button = TopicButton(
402+
stream_id=stream_id,
403+
topic=topic_name,
404+
controller=self.view.controller,
405+
width=self.view.LEFT_WIDTH,
406+
count=self.view.model.unread_counts['unread_topics'].
407+
get((stream_id, canonicalize_topic(topic_name)), 0),
408+
)
409+
self.log.insert(0, updated_topic_button)
397410
self.list_box.set_focus_valign('bottom')
398411
if sender_id == self.view.model.user_id:
399412
self.list_box.set_focus(0)

0 commit comments

Comments
 (0)