Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose_reply: Extract the message quote format into a shared module.

PieterCK7e9cd59568d3
diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.ts
index 549e185b5a0..e8291eb1c3b 100644
--- a/web/src/compose_reply.ts
+++ b/web/src/compose_reply.ts
@@ -439,7 +439,7 @@ function generate_channel_message_quote_context(message: Message): string {
// ```quote
// message content
// ```
- // Keep syntax in sync with channel message reminder format in zerver/lib/reminders.py
+ // Keep syntax in sync with channel message quote format in zerver/lib/compose_reply.py
return $t(
{
defaultMessage: "{username} [said]({link_to_message}) in {topic_link}:",
@@ -469,7 +469,7 @@ function generate_private_message_quote_context(message: Message): string {
// ```quote
// message content
// ```
- // Keep syntax in sync with direct message reminder format in zerver/lib/reminders.py
+ // Keep syntax in sync with direct message quote format in zerver/lib/compose_reply.py
return $t(
{
defaultMessage: "{username} [said]({link_to_message}) to {list_of_recipient_mentions}:",
diff --git a/zerver/lib/compose_reply.py b/zerver/lib/compose_reply.py
new file mode 100644
index 00000000000..ca3ebe4a58a
--- /dev/null
+++ b/zerver/lib/compose_reply.py
@@ -0,0 +1,11 @@
+# The web app composes the same quote-and-reply format in
+# web/src/compose_reply.ts; keep the two in sync.
+from django.utils.translation import gettext_lazy
+
+CHANNEL_MESSAGE_QUOTE_CONTEXT = gettext_lazy(
+ "{user_silent_mention} [said]({conversation_url}) in {topic_pretty_link}:"
+)
+DIRECT_MESSAGE_QUOTE_CONTEXT = gettext_lazy(
+ "{user_silent_mention} [said]({conversation_url}) to {list_of_recipient_mentions}:"
+)
+MESSAGE_QUOTE_BODY = "{fence}quote\n{content}\n{fence}"
diff --git a/zerver/lib/reminders.py b/zerver/lib/reminders.py
index 8e26eaa0eba..be0bfedafc4 100644
--- a/zerver/lib/reminders.py
+++ b/zerver/lib/reminders.py
@@ -2,7 +2,13 @@ from enum import Enum
from django.conf import settings
from django.utils.translation import gettext as _
+from django_stubs_ext import StrPromise
+from zerver.lib.compose_reply import (
+ CHANNEL_MESSAGE_QUOTE_CONTEXT,
+ DIRECT_MESSAGE_QUOTE_CONTEXT,
+ MESSAGE_QUOTE_BODY,
+)
from zerver.lib.display_recipient import get_display_recipient
from zerver.lib.event_types import RemindersRemoveEvent
from zerver.lib.exceptions import JsonableError, ResourceNotFoundError
@@ -121,20 +127,18 @@ def get_reminder_formatted_content(
# Format the message content as a quote.
content += "\n\n"
- REMINDER_FORMAT = {
+ REMINDER_FORMAT: dict[ReminderRecipientType, dict[str, str | StrPromise]] = {
ReminderRecipientType.CHANNEL: {
"widget": _(
"{user_silent_mention} [sent]({conversation_url}) a {widget} in {topic_pretty_link}."
),
- "text": _("{user_silent_mention} [said]({conversation_url}) in {topic_pretty_link}:"),
+ "text": CHANNEL_MESSAGE_QUOTE_CONTEXT,
},
ReminderRecipientType.PRIVATE: {
"widget": _(
"{user_silent_mention} [sent]({conversation_url}) a {widget} to {list_of_recipient_mentions}."
),
- "text": _(
- "{user_silent_mention} [said]({conversation_url}) to {list_of_recipient_mentions}:"
- ),
+ "text": DIRECT_MESSAGE_QUOTE_CONTEXT,
},
ReminderRecipientType.NOTE_TO_SELF: {
"widget": _("You [sent]({conversation_url}) yourself a {widget}."),
@@ -152,15 +156,14 @@ def get_reminder_formatted_content(
content += REMINDER_FORMAT[format_recipient_type_key]["text"].format_map(context)
content += "\n"
fence = get_unused_fence(message.content)
- quoted_message = "{fence}quote\n{msg_content}\n{fence}"
length_without_message_content = len(
- content + quoted_message.format(fence=fence, msg_content="")
+ content + MESSAGE_QUOTE_BODY.format(fence=fence, content="")
)
max_length = settings.MAX_MESSAGE_LENGTH - length_without_message_content
msg_content = truncate_content(message.content, max_length, "\n[message truncated]")
- content += quoted_message.format(
+ content += MESSAGE_QUOTE_BODY.format(
fence=fence,
- msg_content=msg_content,
+ content=msg_content,
)
return content