Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

user_topic: Filter on visibility_policy in muted_topic code.

Abhijeet Prasad Bodas743712c26764
diff --git a/zerver/lib/stream_topic.py b/zerver/lib/stream_topic.py
index eb1b1be71dd..ee0dc935f4e 100644
--- a/zerver/lib/stream_topic.py
+++ b/zerver/lib/stream_topic.py
@@ -19,6 +19,7 @@ class StreamTopicTarget:
query = UserTopic.objects.filter(
stream_id=self.stream_id,
topic_name__iexact=self.topic_name,
+ visibility_policy=UserTopic.MUTED,
).values(
"user_profile_id",
)
diff --git a/zerver/lib/topic_mutes.py b/zerver/lib/topic_mutes.py
index 112eaec301a..6d55229104b 100644
--- a/zerver/lib/topic_mutes.py
+++ b/zerver/lib/topic_mutes.py
@@ -13,7 +13,7 @@ from zerver.models import UserProfile, UserTopic, get_stream
def get_topic_mutes(
user_profile: UserProfile, include_deactivated: bool = False
) -> List[Tuple[str, str, float]]:
- query = UserTopic.objects.filter(user_profile=user_profile)
+ query = UserTopic.objects.filter(user_profile=user_profile, visibility_policy=UserTopic.MUTED)
# Exclude muted topics that are part of deactivated streams unless
# explicitly requested.
if not include_deactivated:
@@ -40,6 +40,7 @@ def set_topic_mutes(
UserTopic.objects.filter(
user_profile=user_profile,
+ visibility_policy=UserTopic.MUTED,
).delete()
if date_muted is None:
@@ -72,6 +73,7 @@ def add_topic_mute(
recipient_id=recipient_id,
topic_name=topic_name,
last_updated=date_muted,
+ visibility_policy=UserTopic.MUTED,
)
@@ -80,6 +82,7 @@ def remove_topic_mute(user_profile: UserProfile, stream_id: int, topic_name: str
user_profile=user_profile,
stream_id=stream_id,
topic_name__iexact=topic_name,
+ visibility_policy=UserTopic.MUTED,
)
row.delete()
@@ -89,6 +92,7 @@ def topic_is_muted(user_profile: UserProfile, stream_id: int, topic_name: str) -
user_profile=user_profile,
stream_id=stream_id,
topic_name__iexact=topic_name,
+ visibility_policy=UserTopic.MUTED,
).exists()
return is_muted
@@ -101,6 +105,7 @@ def exclude_topic_mutes(
# never filtered from the query in this method.
query = UserTopic.objects.filter(
user_profile=user_profile,
+ visibility_policy=UserTopic.MUTED,
)
if stream_id is not None:
@@ -129,7 +134,9 @@ def exclude_topic_mutes(
def build_topic_mute_checker(user_profile: UserProfile) -> Callable[[int, str], bool]:
- rows = UserTopic.objects.filter(user_profile=user_profile).values(
+ rows = UserTopic.objects.filter(
+ user_profile=user_profile, visibility_policy=UserTopic.MUTED
+ ).values(
"recipient_id",
"topic_name",
)
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 58a0edce8d0..8297c6385fe 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -889,7 +889,9 @@ class ImportExportTest(ZulipTestCase):
# test muted topics
def get_muted_topics(r: Realm) -> Set[str]:
user_profile_id = get_user_id(r, hamlet_full_name)
- muted_topics = UserTopic.objects.filter(user_profile_id=user_profile_id)
+ muted_topics = UserTopic.objects.filter(
+ user_profile_id=user_profile_id, visibility_policy=UserTopic.MUTED
+ )
topic_names = {muted_topic.topic_name for muted_topic in muted_topics}
return topic_names
diff --git a/zerver/tests/test_muting_topics.py b/zerver/tests/test_muting_topics.py
index f71a87a518e..c6476ec74ce 100644
--- a/zerver/tests/test_muting_topics.py
+++ b/zerver/tests/test_muting_topics.py
@@ -69,13 +69,17 @@ class MutedTopicsTests(ZulipTestCase):
mute_topic_for_user(hamlet)
user_ids = stream_topic_target.user_ids_muting_topic()
self.assertEqual(user_ids, {hamlet.id})
- hamlet_date_muted = UserTopic.objects.filter(user_profile=hamlet)[0].last_updated
+ hamlet_date_muted = UserTopic.objects.filter(
+ user_profile=hamlet, visibility_policy=UserTopic.MUTED
+ )[0].last_updated
self.assertTrue(timezone_now() - hamlet_date_muted <= timedelta(seconds=100))
mute_topic_for_user(cordelia)
user_ids = stream_topic_target.user_ids_muting_topic()
self.assertEqual(user_ids, {hamlet.id, cordelia.id})
- cordelia_date_muted = UserTopic.objects.filter(user_profile=cordelia)[0].last_updated
+ cordelia_date_muted = UserTopic.objects.filter(
+ user_profile=cordelia, visibility_policy=UserTopic.MUTED
+ )[0].last_updated
self.assertTrue(timezone_now() - cordelia_date_muted <= timedelta(seconds=100))
def test_add_muted_topic(self) -> None: