message_edit: Ignore duplicates when re-muting new topic name.

This avoids an error when a user has already muted the new topic name.
We do this by ignoring duplicates, rather than catching the
IntegrityError, because this edit happens in a transaction, and that
would abort the transaction.
This commit is contained in:
Alex Vandiver 2022-03-24 16:57:32 -07:00 committed by Tim Abbott
parent 141b0c4cec
commit eae4643cb4
2 changed files with 17 additions and 0 deletions

View File

@ -7246,6 +7246,7 @@ def do_update_message(
muting_user,
new_stream if new_stream is not None else stream_being_edited,
topic_name if topic_name is not None else orig_topic_name,
ignore_duplicate=True,
)
send_event(user_profile.realm, event, users_to_be_notified)

View File

@ -1261,9 +1261,11 @@ class EditMessageTest(EditMessageTestCase):
self.subscribe(aaron, stream_name)
self.login_user(aaron)
already_muted_topic = "Already muted topic"
muted_topics = [
[stream_name, "Topic1"],
[stream_name, "Topic2"],
[stream_name, already_muted_topic],
]
set_topic_mutes(hamlet, muted_topics)
set_topic_mutes(cordelia, muted_topics)
@ -1331,6 +1333,20 @@ class EditMessageTest(EditMessageTestCase):
self.assertFalse(topic_is_muted(hamlet, stream.id, change_all_topic_name))
self.assertTrue(topic_is_muted(hamlet, stream.id, change_later_topic_name))
# Make sure we safely handle the case of the new topic being already muted.
check_update_message(
user_profile=hamlet,
message_id=message_id,
stream_id=None,
topic_name=already_muted_topic,
propagate_mode="change_all",
send_notification_to_old_thread=False,
send_notification_to_new_thread=False,
content=None,
)
self.assertFalse(topic_is_muted(hamlet, stream.id, change_later_topic_name))
self.assertTrue(topic_is_muted(hamlet, stream.id, already_muted_topic))
change_one_topic_name = "Topic 1 edited change_one"
check_update_message(
user_profile=hamlet,