From b63f440fb138781d29ba64aee1bc4fea721b20a8 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 14 Apr 2023 19:04:19 +0000 Subject: [PATCH] models: Allow scheduled msgs to store rendered content. This is required by the client to display a list of currently scheduled messages. --- zerver/actions/message_send.py | 4 ++++ .../0435_scheduledmessage_rendered_content.py | 18 ++++++++++++++++++ zerver/models.py | 1 + zerver/tests/test_message_send.py | 2 ++ 4 files changed, 25 insertions(+) create mode 100644 zerver/migrations/0435_scheduledmessage_rendered_content.py diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index b14a32e3c4..0904d0dc9c 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -467,7 +467,11 @@ def do_schedule_messages(send_message_requests: Sequence[SendMessageRequest]) -> scheduled_message.recipient = send_request.message.recipient topic_name = send_request.message.topic_name() scheduled_message.set_topic_name(topic_name=topic_name) + rendering_result = render_markdown( + send_request.message, send_request.message.content, send_request.realm + ) scheduled_message.content = send_request.message.content + scheduled_message.rendered_content = rendering_result.rendered_content scheduled_message.sending_client = send_request.message.sending_client scheduled_message.stream = send_request.stream scheduled_message.realm = send_request.realm diff --git a/zerver/migrations/0435_scheduledmessage_rendered_content.py b/zerver/migrations/0435_scheduledmessage_rendered_content.py new file mode 100644 index 0000000000..e518109a92 --- /dev/null +++ b/zerver/migrations/0435_scheduledmessage_rendered_content.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.5 on 2023-01-16 08:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0434_create_nobody_system_group"), + ] + + operations = [ + migrations.AddField( + model_name="scheduledmessage", + name="rendered_content", + field=models.TextField(default=""), + preserve_default=False, + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 67774d6f47..0b0783a0b6 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -4326,6 +4326,7 @@ class ScheduledMessage(models.Model): recipient = models.ForeignKey(Recipient, on_delete=CASCADE) subject = models.CharField(max_length=MAX_TOPIC_NAME_LENGTH) content = models.TextField() + rendered_content = models.TextField() sending_client = models.ForeignKey(Client, on_delete=CASCADE) stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) realm = models.ForeignKey(Realm, on_delete=CASCADE) diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py index 8cd6f82f01..8fca1a0002 100644 --- a/zerver/tests/test_message_send.py +++ b/zerver/tests/test_message_send.py @@ -1385,6 +1385,7 @@ class ScheduledMessageTest(ZulipTestCase): message = self.last_scheduled_message() self.assert_json_success(result) self.assertEqual(message.content, "Test message 1") + self.assertEqual(message.rendered_content, "

Test message 1

") self.assertEqual(message.topic_name(), "Test topic") self.assertEqual(message.scheduled_timestamp, convert_to_UTC(defer_until)) self.assertEqual(message.delivery_type, ScheduledMessage.SEND_LATER) @@ -1405,6 +1406,7 @@ class ScheduledMessageTest(ZulipTestCase): message = self.last_scheduled_message() self.assert_json_success(result) self.assertEqual(message.content, "Test message 3") + self.assertEqual(message.rendered_content, "

Test message 3

") self.assertEqual(message.scheduled_timestamp, convert_to_UTC(defer_until)) self.assertEqual(message.delivery_type, ScheduledMessage.SEND_LATER)