mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 03:11:54 +00:00
stream_topic: Refactor user_ids_muting_topic.
This refactors and renames user_ids_muting_topic to accept a parameter 'visibility_policy' and fetch user IDs that have a specific visibility_policy(provided as the parameter) set for a topic.
This commit is contained in:
committed by
Tim Abbott
parent
8eec4bf171
commit
409ef040bb
@@ -78,6 +78,7 @@ from zerver.models import (
|
||||
UserMessage,
|
||||
UserPresence,
|
||||
UserProfile,
|
||||
UserTopic,
|
||||
get_client,
|
||||
get_huddle_user_ids,
|
||||
get_stream,
|
||||
@@ -205,7 +206,7 @@ def get_recipient_info(
|
||||
# stream_topic. We may eventually want to have different versions
|
||||
# of this function for different message types.
|
||||
assert stream_topic is not None
|
||||
user_ids_muting_topic = stream_topic.user_ids_muting_topic()
|
||||
user_ids_muting_topic = stream_topic.user_ids_with_visibility_policy(UserTopic.MUTED)
|
||||
|
||||
subscription_rows = (
|
||||
get_subscriptions_for_send_message(
|
||||
|
||||
@@ -15,11 +15,11 @@ class StreamTopicTarget:
|
||||
self.stream_id = stream_id
|
||||
self.topic_name = topic_name
|
||||
|
||||
def user_ids_muting_topic(self) -> Set[int]:
|
||||
def user_ids_with_visibility_policy(self, visibility_policy: int) -> Set[int]:
|
||||
query = UserTopic.objects.filter(
|
||||
stream_id=self.stream_id,
|
||||
topic_name__iexact=self.topic_name,
|
||||
visibility_policy=UserTopic.MUTED,
|
||||
visibility_policy=visibility_policy,
|
||||
).values(
|
||||
"user_profile_id",
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ class MutedTopicsTests(ZulipTestCase):
|
||||
topic_name=topic_name,
|
||||
)
|
||||
|
||||
user_ids = stream_topic_target.user_ids_muting_topic()
|
||||
user_ids = stream_topic_target.user_ids_with_visibility_policy(UserTopic.MUTED)
|
||||
self.assertEqual(user_ids, set())
|
||||
|
||||
def mute_topic_for_user(user: UserProfile) -> None:
|
||||
@@ -67,7 +67,7 @@ class MutedTopicsTests(ZulipTestCase):
|
||||
)
|
||||
|
||||
mute_topic_for_user(hamlet)
|
||||
user_ids = stream_topic_target.user_ids_muting_topic()
|
||||
user_ids = stream_topic_target.user_ids_with_visibility_policy(UserTopic.MUTED)
|
||||
self.assertEqual(user_ids, {hamlet.id})
|
||||
hamlet_date_muted = UserTopic.objects.filter(
|
||||
user_profile=hamlet, visibility_policy=UserTopic.MUTED
|
||||
@@ -75,7 +75,7 @@ class MutedTopicsTests(ZulipTestCase):
|
||||
self.assertTrue(timezone_now() - hamlet_date_muted <= timedelta(seconds=100))
|
||||
|
||||
mute_topic_for_user(cordelia)
|
||||
user_ids = stream_topic_target.user_ids_muting_topic()
|
||||
user_ids = stream_topic_target.user_ids_with_visibility_policy(UserTopic.MUTED)
|
||||
self.assertEqual(user_ids, {hamlet.id, cordelia.id})
|
||||
cordelia_date_muted = UserTopic.objects.filter(
|
||||
user_profile=cordelia, visibility_policy=UserTopic.MUTED
|
||||
|
||||
Reference in New Issue
Block a user