Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_edit: Don't add content edit to all messages.
Aman Agrawalebe822341d7e
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 1ab312ff02a..03945750a53 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -5562,9 +5562,22 @@ def do_update_message(edit_history_event[LEGACY_PREV_TOPIC] = orig_topic_nameupdate_edit_history(message, timestamp, edit_history_event)+delete_event_notify_user_ids: List[int] = []if propagate_mode in ["change_later", "change_all"]:assert topic_name is not None or new_stream is not None+ # Other messages should only get topic/stream fields in their edit history.+ topic_only_edit_history_event = {+ k: v+ for (k, v) in edit_history_event.items()+ if k+ not in [+ "prev_content",+ "prev_rendered_content",+ "prev_rendered_content_version",+ ]+ }+messages_list = update_messages_for_topic_edit(edited_message=message,propagate_mode=propagate_mode,@@ -5572,7 +5585,7 @@ def do_update_message(topic_name=topic_name,new_stream=new_stream,old_recipient_id=old_recipient_id,- edit_history_event=edit_history_event,+ edit_history_event=topic_only_edit_history_event,last_edit_time=timestamp,)changed_messages += messages_listdiff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.pyindex e0b58d93132..247438ca406 100644--- a/zerver/tests/test_message_edit.py+++ b/zerver/tests/test_message_edit.py@@ -938,6 +938,48 @@ class EditMessageTest(ZulipTestCase):self.assert_json_success(result)verify_edit_history(new_topic, 2)+ def test_topic_and_content_edit(self) -> None:+ self.login("hamlet")+ id1 = self.send_stream_message(+ self.example_user("hamlet"), "Scotland", "message 1", "topic"+ )+ id2 = self.send_stream_message(self.example_user("iago"), "Scotland", "message 2", "topic")+ id3 = self.send_stream_message(+ self.example_user("hamlet"), "Scotland", "message 3", "topic"+ )++ new_topic = "edited"+ result = self.client_patch(+ "/json/messages/" + str(id1),+ {+ "message_id": id1,+ "topic": new_topic,+ "propagate_mode": "change_later",+ "content": "edited message",+ },+ )++ self.assert_json_success(result)++ # Content change of only id1 should come in edit history+ # and topic change should be present in all the messages.+ msg1 = Message.objects.get(id=id1)+ msg2 = Message.objects.get(id=id2)+ msg3 = Message.objects.get(id=id3)++ msg1_edit_history = orjson.loads(msg1.edit_history)+ self.assertTrue("prev_content" in msg1_edit_history[0].keys())++ for msg in [msg2, msg3]:+ self.assertFalse("prev_content" in orjson.loads(msg.edit_history)[0].keys())++ for msg in [msg1, msg2, msg3]:+ self.assertEqual(+ new_topic,+ msg.topic_name(),+ )+ self.assertEqual(len(orjson.loads(msg.edit_history)), 1)+def test_propagate_topic_forward(self) -> None:self.login("hamlet")id1 = self.send_stream_message(self.example_user("hamlet"), "Scotland", topic_name="topic1")