muting: Add a flag to allow user duplicate mutes to silently succeed.

This commit is contained in:
Alex Vandiver 2022-03-24 16:42:12 -07:00 committed by Tim Abbott
parent 2762121162
commit 781107308d
2 changed files with 22 additions and 8 deletions

View File

@ -8031,10 +8031,18 @@ def do_mute_topic(
stream: Stream,
topic: str,
date_muted: Optional[datetime.datetime] = None,
ignore_duplicate: bool = False,
) -> None:
if date_muted is None:
date_muted = timezone_now()
add_topic_mute(user_profile, stream.id, stream.recipient_id, topic, date_muted)
add_topic_mute(
user_profile,
stream.id,
stream.recipient_id,
topic,
date_muted,
ignore_duplicate=ignore_duplicate,
)
event = dict(type="muted_topics", muted_topics=get_topic_mutes(user_profile))
send_event(user_profile.realm, event, [user_profile.id])

View File

@ -65,16 +65,22 @@ def add_topic_mute(
recipient_id: int,
topic_name: str,
date_muted: Optional[datetime.datetime] = None,
ignore_duplicate: bool = False,
) -> None:
if date_muted is None:
date_muted = timezone_now()
UserTopic.objects.create(
user_profile=user_profile,
stream_id=stream_id,
recipient_id=recipient_id,
topic_name=topic_name,
last_updated=date_muted,
visibility_policy=UserTopic.MUTED,
UserTopic.objects.bulk_create(
[
UserTopic(
user_profile=user_profile,
stream_id=stream_id,
recipient_id=recipient_id,
topic_name=topic_name,
last_updated=date_muted,
visibility_policy=UserTopic.MUTED,
),
],
ignore_conflicts=ignore_duplicate,
)