message_reminders: Add support for notes.

This commit adds the ability for users to include notes
with their message reminders.

Fixes #35070.

Co-Authored-By: Aman Agrawal <amanagr@zulip.com>
This commit is contained in:
Kislay Verma
2025-08-07 19:43:40 +05:30
committed by Tim Abbott
parent 45d4df8dc2
commit f0a88d51cc
22 changed files with 209 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
from django.conf import settings
from django.utils.translation import gettext as _
from zerver.lib.exceptions import ResourceNotFoundError
from zerver.lib.exceptions import JsonableError, ResourceNotFoundError
from zerver.lib.markdown.fenced_code import get_unused_fence
from zerver.lib.mention import silent_mention_syntax_for_user
from zerver.lib.message import truncate_content
@@ -12,7 +12,26 @@ from zerver.models import Message, Stream, UserProfile
from zerver.models.scheduled_jobs import ScheduledMessage
def get_reminder_formatted_content(message: Message, current_user: UserProfile) -> str:
def normalize_note_text(body: str) -> str:
# Similar to zerver.lib.message.normalize_body
body = body.rstrip().lstrip("\n")
if len(body) > settings.MAX_REMINDER_NOTE_LENGTH:
raise JsonableError(
_("Maximum reminder note length: {max_length} characters").format(
max_length=settings.MAX_REMINDER_NOTE_LENGTH
)
)
return body
def get_reminder_formatted_content(
message: Message, current_user: UserProfile, note: str | None = None
) -> str:
if note:
note = normalize_note_text(note)
if message.is_stream_message():
# We don't need to check access here since we already have the message
# whose access has already been checked by the caller.
@@ -20,16 +39,32 @@ def get_reminder_formatted_content(message: Message, current_user: UserProfile)
id=message.recipient.type_id,
realm=current_user.realm,
)
content = _("You requested a reminder for {message_pretty_link}.").format(
message_pretty_link=get_message_link_syntax(
stream_id=stream.id,
stream_name=stream.name,
topic_name=message.topic_name(),
message_id=message.id,
)
message_pretty_link = get_message_link_syntax(
stream_id=stream.id,
stream_name=stream.name,
topic_name=message.topic_name(),
message_id=message.id,
)
if note:
content = _(
"You requested a reminder for {message_pretty_link}. Note:\n > {note}"
).format(
message_pretty_link=message_pretty_link,
note=note,
)
else:
content = _("You requested a reminder for {message_pretty_link}.").format(
message_pretty_link=message_pretty_link,
)
else:
content = _("You requested a reminder for the following direct message.")
if note:
content = _(
"You requested a reminder for the following direct message. Note:\n > {note}"
).format(
note=note,
)
else:
content = _("You requested a reminder for the following direct message.")
# Format the message content as a quote.
user_silent_mention = silent_mention_syntax_for_user(message.sender)