streams: Mark messages as read only for unsubscribed streams.

Previously, we were marking messages of all the streams passed
to bulk_remove_subscriptions even if user was not subscribed
to some of them and those streams would ideally not have
any unread messages. This code was added in 766511e519.

This commit changes the code to only mark messages of actually
unsubscribed streams as read.
This commit is contained in:
Sahil Batra
2022-05-12 13:07:13 +05:30
committed by Alex Vandiver
parent 1e453633b0
commit 0bfe973b65
2 changed files with 6 additions and 4 deletions

View File

@@ -607,7 +607,9 @@ def bulk_remove_subscriptions(
event = {
"type": "mark_stream_messages_as_read",
"user_profile_id": user_profile.id,
"stream_recipient_ids": [stream.recipient_id for stream in streams],
"stream_recipient_ids": [
stream.recipient_id for stream in streams_by_user[user_profile.id]
],
}
queue_json_publish("deferred_work", event)

View File

@@ -4668,10 +4668,10 @@ class SubscriptionAPITest(ZulipTestCase):
self.subscribe(user3, "private_stream")
# Apart from 3 peer-remove events and 2 unsubscribe event, because `bulk_remove_subscriptions`
# also marks are read messages in those streams as read, so emits 8 `message_flags` events too
# also marks are read messages in those streams as read, so emits 6 `message_flags` events too
# (for each of the notification bot messages).
events: List[Mapping[str, Any]] = []
with self.tornado_redirected_to_list(events, expected_num_events=13):
with self.tornado_redirected_to_list(events, expected_num_events=11):
with queries_captured() as query_count:
with cache_tries_captured() as cache_count:
bulk_remove_subscriptions(
@@ -4681,7 +4681,7 @@ class SubscriptionAPITest(ZulipTestCase):
acting_user=None,
)
self.assert_length(query_count, 27)
self.assert_length(query_count, 23)
self.assert_length(cache_count, 3)
peer_events = [e for e in events if e["event"].get("op") == "peer_remove"]