mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
Exclude muted topics from unread count.
This commit is contained in:
@@ -14,6 +14,7 @@ from zerver.lib.cache import cache_with_key, to_dict_cache_key
|
|||||||
from zerver.lib.request import JsonableError
|
from zerver.lib.request import JsonableError
|
||||||
from zerver.lib.str_utils import force_bytes, dict_with_str_keys
|
from zerver.lib.str_utils import force_bytes, dict_with_str_keys
|
||||||
from zerver.lib.timestamp import datetime_to_timestamp
|
from zerver.lib.timestamp import datetime_to_timestamp
|
||||||
|
from zerver.lib.topic_mutes import build_topic_mute_checker
|
||||||
|
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
get_display_recipient_by_id,
|
get_display_recipient_by_id,
|
||||||
@@ -448,10 +449,23 @@ def get_unread_message_ids_per_recipient(user_profile):
|
|||||||
rows = list(reversed(user_msgs))
|
rows = list(reversed(user_msgs))
|
||||||
|
|
||||||
muted_recipient_ids = get_muted_recipient_ids(user_profile)
|
muted_recipient_ids = get_muted_recipient_ids(user_profile)
|
||||||
active_stream_rows = [
|
|
||||||
row for row in rows
|
topic_mute_checker = build_topic_mute_checker(user_profile)
|
||||||
if row['message__recipient_id'] not in muted_recipient_ids
|
|
||||||
]
|
def is_row_muted(row):
|
||||||
|
# type: (Dict[str, Any]) -> bool
|
||||||
|
recipient_id = row['message__recipient_id']
|
||||||
|
|
||||||
|
if recipient_id in muted_recipient_ids:
|
||||||
|
return True
|
||||||
|
|
||||||
|
topic_name = row['message__subject']
|
||||||
|
if topic_mute_checker(recipient_id, topic_name):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
active_stream_rows = [row for row in rows if not is_row_muted(row)]
|
||||||
|
|
||||||
count = len(active_stream_rows)
|
count = len(active_stream_rows)
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ from zerver.lib.test_helpers import POSTRequestMock, get_subscription, \
|
|||||||
from zerver.lib.test_classes import (
|
from zerver.lib.test_classes import (
|
||||||
ZulipTestCase,
|
ZulipTestCase,
|
||||||
)
|
)
|
||||||
|
from zerver.lib.topic_mutes import (
|
||||||
|
add_topic_mute,
|
||||||
|
)
|
||||||
from zerver.lib.validator import (
|
from zerver.lib.validator import (
|
||||||
check_bool, check_dict, check_dict_only, check_float, check_int, check_list, check_string,
|
check_bool, check_dict, check_dict_only, check_float, check_int, check_list, check_string,
|
||||||
equals, check_none_or, Validator
|
equals, check_none_or, Validator
|
||||||
@@ -1655,12 +1658,26 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||||||
subscription.in_home_view = False
|
subscription.in_home_view = False
|
||||||
subscription.save()
|
subscription.save()
|
||||||
|
|
||||||
|
def mute_topic(user_profile, stream_name, topic_name):
|
||||||
|
# type: (UserProfile, Text, Text) -> None
|
||||||
|
stream = get_stream(stream_name, realm)
|
||||||
|
recipient = get_recipient(Recipient.STREAM, stream.id)
|
||||||
|
|
||||||
|
add_topic_mute(
|
||||||
|
user_profile=user_profile,
|
||||||
|
stream_id=stream.id,
|
||||||
|
recipient_id=recipient.id,
|
||||||
|
topic_name='muted-topic',
|
||||||
|
)
|
||||||
|
|
||||||
cordelia = self.example_user('cordelia')
|
cordelia = self.example_user('cordelia')
|
||||||
sender_id = cordelia.id
|
sender_id = cordelia.id
|
||||||
sender_email = cordelia.email
|
sender_email = cordelia.email
|
||||||
user_profile = self.example_user('hamlet')
|
user_profile = self.example_user('hamlet')
|
||||||
othello = self.example_user('othello')
|
othello = self.example_user('othello')
|
||||||
|
|
||||||
|
realm = user_profile.realm
|
||||||
|
|
||||||
# our tests rely on order
|
# our tests rely on order
|
||||||
assert(sender_email < user_profile.email)
|
assert(sender_email < user_profile.email)
|
||||||
assert(user_profile.email < othello.email)
|
assert(user_profile.email < othello.email)
|
||||||
@@ -1670,8 +1687,12 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||||||
|
|
||||||
muted_stream = self.subscribe(user_profile, 'Muted Stream')
|
muted_stream = self.subscribe(user_profile, 'Muted Stream')
|
||||||
mute_stream(user_profile, muted_stream)
|
mute_stream(user_profile, muted_stream)
|
||||||
|
mute_topic(user_profile, 'Denmark', 'muted-topic')
|
||||||
|
|
||||||
stream_message_id = self.send_message(sender_email, "Denmark", Recipient.STREAM, "hello")
|
stream_message_id = self.send_message(sender_email, "Denmark", Recipient.STREAM, "hello")
|
||||||
muted_stream_message_id = self.send_message(sender_email, "Muted Stream", Recipient.STREAM, "hello")
|
muted_stream_message_id = self.send_message(sender_email, "Muted Stream", Recipient.STREAM, "hello")
|
||||||
|
muted_topic_message_id = self.send_message(sender_email, "Denmark", Recipient.STREAM,
|
||||||
|
subject="muted-topic", content="hello")
|
||||||
|
|
||||||
huddle_message_id = self.send_message(sender_email,
|
huddle_message_id = self.send_message(sender_email,
|
||||||
[user_profile.email, othello.email],
|
[user_profile.email, othello.email],
|
||||||
@@ -1696,10 +1717,15 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||||||
|
|
||||||
unread_stream = result['streams'][0]
|
unread_stream = result['streams'][0]
|
||||||
self.assertEqual(unread_stream['stream_id'], get_stream('Denmark', user_profile.realm).id)
|
self.assertEqual(unread_stream['stream_id'], get_stream('Denmark', user_profile.realm).id)
|
||||||
|
self.assertEqual(unread_stream['topic'], 'muted-topic')
|
||||||
|
self.assertEqual(unread_stream['unread_message_ids'], [muted_topic_message_id])
|
||||||
|
|
||||||
|
unread_stream = result['streams'][1]
|
||||||
|
self.assertEqual(unread_stream['stream_id'], get_stream('Denmark', user_profile.realm).id)
|
||||||
self.assertEqual(unread_stream['topic'], 'test')
|
self.assertEqual(unread_stream['topic'], 'test')
|
||||||
self.assertEqual(unread_stream['unread_message_ids'], [stream_message_id])
|
self.assertEqual(unread_stream['unread_message_ids'], [stream_message_id])
|
||||||
|
|
||||||
unread_stream = result['streams'][1]
|
unread_stream = result['streams'][2]
|
||||||
self.assertEqual(unread_stream['stream_id'], get_stream('Muted Stream', user_profile.realm).id)
|
self.assertEqual(unread_stream['stream_id'], get_stream('Muted Stream', user_profile.realm).id)
|
||||||
self.assertEqual(unread_stream['topic'], 'test')
|
self.assertEqual(unread_stream['topic'], 'test')
|
||||||
self.assertEqual(unread_stream['unread_message_ids'], [muted_stream_message_id])
|
self.assertEqual(unread_stream['unread_message_ids'], [muted_stream_message_id])
|
||||||
|
|||||||
Reference in New Issue
Block a user