Skip to content

Commit 013e101

Browse files
committed
helper: Index case insensitive topic names by narrowed topic.
Currently, the topic indexing conditional in index_messages does case sensitive comparison with narrowed topic and msg_topic which results in similar topic names (case insensitive) not getting indexed at all. This performs lowercase comparison and indexes messages by the narrowed topic. For the latter part, if it finds a similar topic name already indexed, it updates that topic name (key) with the matching [lowercase] narrowed topic. Consequently, topic narrow from the topic list (for the latest topic name) or from 'All Messages'/stream narrow (for any of the similar topic name), contains all the messages.
1 parent c51de88 commit 013e101

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

zulipterminal/helper.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,27 @@ def index_messages(messages: List[Message],
406406
if msg['type'] == 'stream' and len(narrow) == 2:
407407
narrow_topic = narrow[1][1]
408408
msg_topic = msg['subject']
409-
if narrow_topic == msg_topic:
409+
# Do a lowercase comparison to acknowledge case insensitive topic
410+
# names. For instance, case, CASE and cAsE.
411+
if narrow_topic.lower() == msg_topic.lower():
410412
topics_in_stream = index['topic_msg_ids'][msg['stream_id']]
411-
if not topics_in_stream.get(msg_topic):
412-
topics_in_stream[msg_topic] = set()
413-
topics_in_stream[msg_topic].add(msg['id'])
413+
lowercase_topic_names = map(str.lower, topics_in_stream)
414+
415+
# Update existing topic name key for the narrowed topic with
416+
# narrow_topic.
417+
# NOTE: lowercase_topic_names doesn't need to be updated.
418+
for topic_name in topics_in_stream:
419+
if topic_name.lower() == narrow_topic.lower():
420+
existing_ids = topics_in_stream[topic_name]
421+
del topics_in_stream[topic_name]
422+
topics_in_stream[narrow_topic] = existing_ids
423+
break
424+
425+
# Use narrow_topic as a key in the index (topics_in_stream) to
426+
# unify case insensitive topic names.
427+
if msg_topic.lower() not in lowercase_topic_names:
428+
topics_in_stream[narrow_topic] = set()
429+
topics_in_stream[narrow_topic].add(msg['id'])
414430

415431
return index
416432

0 commit comments

Comments
 (0)