zulip/zerver/lib/reminders.py
Aman Agrawal 733817cb51
Some checks failed
Code scanning / CodeQL (push) Has been cancelled
Zulip production suite / Ubuntu 22.04 production build (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:bookworm, true, false, Debian 12 (Python 3.11, backend + documentation), bookworm) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:jammy, false, true, Ubuntu 22.04 (Python 3.10, backend + frontend), jammy) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:noble, false, false, Ubuntu 24.04 (Python 3.12, backend), noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm, --test-custom-db, Debian 12 production install with custom db name and user, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy, , Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble, , Ubuntu 24.04 production install, noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-7.0, 7.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-8.0, 8.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy-6.0, 6.0 Version Upgrade, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble-10.0, 10.0 Version Upgrade, noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble-9.0, 9.0 Version Upgrade, noble) (push) Has been cancelled
reminders: Add API endpoint to schedule reminders.
2025-05-02 16:48:00 -07:00

52 lines
2.1 KiB
Python

from django.conf import settings
from django.utils.translation import gettext as _
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
from zerver.lib.message_cache import MessageDict
from zerver.lib.url_encoding import near_message_url, topic_narrow_url
from zerver.models import Message, Stream, UserProfile
def get_reminder_formatted_content(message: Message, current_user: UserProfile) -> str:
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.
stream = Stream.objects.get(
id=message.recipient.type_id,
realm=current_user.realm,
)
narrow_link = topic_narrow_url(
realm=current_user.realm,
stream=stream,
topic_name=message.topic_name(),
)
content = _(
"You requested a reminder for the following message sent to [{stream_name} > {topic_name}]({narrow_link})."
).format(
stream_name=stream.name,
topic_name=message.topic_name(),
narrow_link=narrow_link,
)
else:
content = _("You requested a reminder for the following direct message.")
# Format the message content as a quote.
content += "\n\n"
content += _("{user_silent_mention} [said]({conversation_url}):").format(
user_silent_mention=silent_mention_syntax_for_user(message.sender),
conversation_url=near_message_url(current_user.realm, MessageDict.wide_dict(message)),
)
content += "\n"
fence = get_unused_fence(content)
quoted_message = "{fence}quote\n{msg_content}\n{fence}"
content += quoted_message
length_without_message_content = len(content.format(fence=fence, msg_content=""))
max_length = settings.MAX_MESSAGE_LENGTH - length_without_message_content
msg_content = truncate_content(message.content, max_length, "\n[message truncated]")
return content.format(
fence=fence,
msg_content=msg_content,
)