From f4ca8025dab4ee16f4aa04e92de746b230039fc4 Mon Sep 17 00:00:00 2001 From: Pedro Almeida Date: Thu, 27 Jun 2024 19:02:07 +0100 Subject: [PATCH] move_stream: Trigger only move notification. This commit updates the code so that only the moved notification is triggered when moving a message between a resolved and unresolved topic in different streams or when moving a topic itself. This change takes place even when both stream change and resolve or unresolve a topic takes place in the same API request, as we now consider it only a move operation. This fixes a case where a message is moved between topics that have the same name, but one resolved and another unresolved and in different streams. Previously a resolved or unresolved notification would also be sent. Now, this will not happen, ensuring only the move operation is notified. Fixes part of #29007. --- zerver/actions/message_edit.py | 14 +++----------- zerver/tests/test_message_move_stream.py | 14 +++----------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py index 77f82c2849..95d290faae 100644 --- a/zerver/actions/message_edit.py +++ b/zerver/actions/message_edit.py @@ -1039,20 +1039,12 @@ def do_update_message( resolved_topic_message_id = None resolved_topic_message_deleted = False - if topic_name is not None and content is None: - # When stream is changed and topic is marked as resolved or unresolved - # in the same API request, resolved or unresolved notification should - # be sent to "new_stream". - # In general, it is sent to "stream_being_edited". - stream_to_send_resolve_topic_notification = stream_being_edited - if new_stream is not None: - stream_to_send_resolve_topic_notification = new_stream - - assert stream_to_send_resolve_topic_notification is not None + if topic_name is not None and content is None and new_stream is None: + assert stream_being_edited is not None resolved_topic_message_id, resolved_topic_message_deleted = ( maybe_send_resolve_topic_notifications( user_profile=user_profile, - stream=stream_to_send_resolve_topic_notification, + stream=stream_being_edited, old_topic_name=orig_topic_name, new_topic_name=topic_name, changed_messages=changed_messages, diff --git a/zerver/tests/test_message_move_stream.py b/zerver/tests/test_message_move_stream.py index b8a0ca5cae..eefa5e1971 100644 --- a/zerver/tests/test_message_move_stream.py +++ b/zerver/tests/test_message_move_stream.py @@ -1441,13 +1441,9 @@ class MessageMoveStreamTest(ZulipTestCase): ) self.assert_json_success(result) messages = get_topic_messages(user_profile, new_stream, new_topic_name) - self.assert_length(messages, 5) + self.assert_length(messages, 4) self.assertEqual( messages[3].content, - f"@_**{user_profile.full_name}|{user_profile.id}** has marked this topic as resolved.", - ) - self.assertEqual( - messages[4].content, f"This topic was moved here from #**{first_stream.name}>test** by @_**{user_profile.full_name}|{user_profile.id}**.", ) @@ -1464,13 +1460,9 @@ class MessageMoveStreamTest(ZulipTestCase): ) self.assert_json_success(result) messages = get_topic_messages(user_profile, new_stream, new_topic_name) - self.assert_length(messages, 7) + self.assert_length(messages, 5) self.assertEqual( - messages[5].content, - f"@_**{user_profile.full_name}|{user_profile.id}** has marked this topic as unresolved.", - ) - self.assertEqual( - messages[6].content, + messages[4].content, f"This topic was moved here from #**{second_stream.name}>✔ test** by @_**{user_profile.full_name}|{user_profile.id}**.", )