Skip to content

Commit

Permalink
model: Use the sort_unread_topics method to sort unread topics.
Browse files Browse the repository at this point in the history
This commit introduces the sort_unread_topics function to sort
according to stream names instead of stream id. This also replaces
the use of bisect and is removed.
  • Loading branch information
theViz343 committed Sep 8, 2023
1 parent ddddb4c commit 13e8d63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Defines the `Model`, fetching and storing data retrieved from the Zulip server
"""

import bisect
import itertools
import json
import time
Expand Down Expand Up @@ -65,6 +64,7 @@
StreamData,
TidiedUserInfo,
UserStatus,
sort_unread_topics,
asynch,
canonicalize_color,
classify_unread_counts,
Expand Down Expand Up @@ -911,7 +911,10 @@ def next_unread_topic_from_message_id(
self.stream_id_from_name(self.narrow[0][1]),
self.narrow[1][1],
)
unread_topics = sorted(self.unread_counts["unread_topics"].keys())
unread_topics = sort_unread_topics(
self.unread_counts["unread_topics"],
self.pinned_streams + self.unpinned_streams,
)
next_topic = False
stream_start: Optional[Tuple[int, str]] = None
if current_topic is None:
Expand All @@ -921,7 +924,10 @@ def next_unread_topic_from_message_id(
# current_topic is not in unread_topics, and the next unmuted topic
# is to be returned. This does not modify the original unread topics
# data, and is just used to compute the next unmuted topic to be returned.
bisect.insort(unread_topics, current_topic)
unread_topics = sort_unread_topics(
{**self.unread_counts["unread_topics"], current_topic: 0},
self.pinned_streams + self.unpinned_streams,
)
# loop over unread_topics list twice for the case that last_unread_topic was
# the last valid unread_topic in unread_topics list.
for unread_topic in unread_topics * 2:
Expand Down

0 comments on commit 13e8d63

Please sign in to comment.