user_topics: Refactor remove_topic_mute.

This commit replaces 'remove_topic_mute' with
'set_user_topic_visibility_policy_in_database' and
updates it to delete UserTopic row with any configured
visibility_policy and not just muting.
This commit is contained in:
Kartik Srivastava
2022-09-21 19:21:48 +05:30
committed by Tim Abbott
parent f844cb6dad
commit e9cf2659cf
3 changed files with 25 additions and 17 deletions

View File

@@ -8,7 +8,6 @@ from zerver.lib.exceptions import JsonableError
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.user_topics import (
get_topic_mutes,
remove_topic_mute,
set_user_topic_visibility_policy_in_database,
)
from zerver.models import Stream, UserProfile, UserTopic
@@ -30,9 +29,11 @@ def do_set_user_topic_visibility_policy(
if visibility_policy == UserTopic.VISIBILITY_POLICY_INHERIT:
try:
remove_topic_mute(user_profile, stream.id, topic)
set_user_topic_visibility_policy_in_database(
user_profile, stream.id, topic, visibility_policy=visibility_policy
)
except UserTopic.DoesNotExist:
raise JsonableError(_("Topic is not muted"))
raise JsonableError(_("Nothing to be done"))
else:
assert stream.recipient_id is not None
set_user_topic_visibility_policy_in_database(