Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import datetime
|
|
|
|
from django.db import transaction
|
|
|
|
from zerver.actions.message_send import check_message
|
|
from zerver.actions.scheduled_messages import do_schedule_messages
|
|
from zerver.lib.addressee import Addressee
|
|
from zerver.lib.message import access_message
|
|
from zerver.lib.reminders import get_reminder_formatted_content, notify_remove_reminder
|
|
from zerver.models import Client, ScheduledMessage, UserProfile
|
|
|
|
|
|
def schedule_reminder_for_message(
|
|
current_user: UserProfile,
|
|
client: Client,
|
|
message_id: int,
|
|
deliver_at: datetime.datetime,
|
|
note: str,
|
|
) -> int:
|
|
message = access_message(current_user, message_id, is_modifying_message=False)
|
|
# Even though reminder will be sent from NOTIFICATION_BOT, we still
|
|
# set current_user as the sender here to help us make the permission checks easier.
|
|
addressee = Addressee.for_user_profile(current_user)
|
|
# This can raise an exception in the unlikely event that the current user cannot DM themself.
|
|
send_request = check_message(
|
|
current_user,
|
|
client,
|
|
addressee,
|
|
get_reminder_formatted_content(message, current_user, note),
|
|
current_user.realm,
|
|
)
|
|
send_request.deliver_at = deliver_at
|
|
send_request.reminder_target_message_id = message_id
|
|
send_request.reminder_note = note
|
|
|
|
return do_schedule_messages(
|
|
[send_request],
|
|
current_user,
|
|
read_by_sender=False,
|
|
delivery_type=ScheduledMessage.REMIND,
|
|
)[0]
|
|
|
|
|
|
@transaction.atomic(durable=True)
|
|
def do_delete_reminder(user_profile: UserProfile, reminder: ScheduledMessage) -> None:
|
|
assert reminder.delivery_type == ScheduledMessage.REMIND
|
|
reminder_id = reminder.id
|
|
reminder.delete()
|
|
notify_remove_reminder(user_profile, reminder_id)
|