Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
muted_topics: Clean up unmute topic event code duplication.
Tim Abbottbd04733c0f5a
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex 26d611ce4af..73877065f64 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -50,7 +50,7 @@ from zerver.lib.topic import ()from zerver.lib.types import EditHistoryEventfrom zerver.lib.user_message import UserMessageLite, bulk_insert_ums-from zerver.lib.user_topics import get_users_muting_topic, remove_topic_mute+from zerver.lib.user_topics import get_users_muting_topicfrom zerver.lib.widget import is_widget_messagefrom zerver.models import (ArchivedAttachment,@@ -61,7 +61,6 @@ from zerver.models import (Stream,UserMessage,UserProfile,- UserTopic,get_stream_by_id_in_realm,get_system_bot,)@@ -799,22 +798,18 @@ def do_update_message(# access. Unmute the topic for such users.do_unmute_topic(muting_user, stream_being_edited, orig_topic_name)else:- # Otherwise, we move the muted topic record for the user.- # We call remove_topic_mute rather than do_unmute_topic to- # avoid sending two events with new muted topics in- # immediate succession; this is correct only because- # muted_topics events always send the full set of topics.- remove_topic_mute(muting_user, stream_being_edited.id, orig_topic_name)-- date_unmuted = timezone_now()- user_topic_event: Dict[str, Any] = {- "type": "user_topic",- "stream_id": stream_being_edited.id,- "topic_name": orig_topic_name,- "last_updated": datetime_to_timestamp(date_unmuted),- "visibility_policy": UserTopic.VISIBILITY_POLICY_INHERIT,- }- send_event(user_profile.realm, user_topic_event, [user_profile.id])+ # Otherwise, we move the muted topic record for the+ # user, but removing the old topic mute and then+ # creating a new one.+ do_unmute_topic(+ muting_user,+ stream_being_edited,+ orig_topic_name,+ # do_mute_topic will send an updated muted topic+ # event, which contains the full set of muted+ # topics, just after this.+ skip_muted_topics_event=True,+ )do_mute_topic(muting_user,diff --git a/zerver/actions/user_topics.py b/zerver/actions/user_topics.pyindex f1fda71907d..60889d2d610 100644--- a/zerver/actions/user_topics.py+++ b/zerver/actions/user_topics.py@@ -47,7 +47,9 @@ def do_mute_topic(send_event(user_profile.realm, user_topic_event, [user_profile.id])-def do_unmute_topic(user_profile: UserProfile, stream: Stream, topic: str) -> None:+def do_unmute_topic(+ user_profile: UserProfile, stream: Stream, topic: str, *, skip_muted_topics_event: bool = False+) -> None:# Note: If you add any new code to this function, the# remove_topic_mute call in do_update_message will need to be# updated for correctness.@@ -59,8 +61,9 @@ def do_unmute_topic(user_profile: UserProfile, stream: Stream, topic: str) -> No# This first muted_topics event is deprecated and will be removed# once clients are migrated to handle the user_topic event type# instead.- muted_topics_event = dict(type="muted_topics", muted_topics=get_topic_mutes(user_profile))- send_event(user_profile.realm, muted_topics_event, [user_profile.id])+ if not skip_muted_topics_event:+ muted_topics_event = dict(type="muted_topics", muted_topics=get_topic_mutes(user_profile))+ send_event(user_profile.realm, muted_topics_event, [user_profile.id])date_unmuted = timezone_now()