Skip to content

Commit

Permalink
model: Add stream wrap-around behavior to next unread topic algorithm.
Browse files Browse the repository at this point in the history
This commit aims to introduce in-stream wrap-around behavior to the
next_unread_topic_from_message_id function if there are unread messages
still present in the current stream.

Test case added.
  • Loading branch information
theViz343 committed Aug 7, 2023
1 parent b0d87c2 commit 946b833
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4010,6 +4010,12 @@ def test_is_muted_topic(
(1, "topic1"),
id="unmuted_unread_not_present_in_next_stream_as_current_topic_not_in_unread_list",
),
case(
{(1, "topic1"), (1, "topic11"), (2, "topic2")},
(1, "topic11"),
(1, "topic1"),
id="unread_present_in_same_stream_wrap_around",
),
],
)
def test_get_next_unread_topic(
Expand Down
30 changes: 22 additions & 8 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ def next_unread_topic_from_message_id(
current_topic = self.stream_topic_from_message_id(current_message)
unread_topics = sorted(self.unread_counts["unread_topics"].keys())
next_topic = False
stream_start = None
if current_topic is None:
next_topic = True
elif current_topic not in unread_topics:
Expand All @@ -919,14 +920,27 @@ def next_unread_topic_from_message_id(
# the last valid unread_topic in unread_topics list.
for unread_topic in unread_topics * 2:
stream_id, topic_name = unread_topic
if (
not self.is_muted_topic(stream_id, topic_name)
and not self.is_muted_stream(stream_id)
and next_topic
):
if unread_topic == current_topic:
return None
return unread_topic
if not self.is_muted_topic(
stream_id, topic_name
) and not self.is_muted_stream(stream_id):
if next_topic:
if unread_topic == current_topic:
return None
elif (
current_topic is None
or unread_topic[0] == current_topic[0]
or stream_start == current_topic
):
return unread_topic
else:
return stream_start

if (
not stream_start
and current_topic is not None
and unread_topic[0] == current_topic[0]
):
stream_start = unread_topic
if unread_topic == current_topic:
next_topic = True
return None
Expand Down

0 comments on commit 946b833

Please sign in to comment.