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
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
from django.utils.translation import gettext as _
|
|
|
|
from zerver.lib.exceptions import ResourceNotFoundError
|
|
from zerver.models import ScheduledMessage, UserProfile
|
|
from zerver.models.scheduled_jobs import (
|
|
APIReminderDirectMessageDict,
|
|
APIScheduledDirectMessageDict,
|
|
APIScheduledStreamMessageDict,
|
|
)
|
|
|
|
|
|
def access_scheduled_message(
|
|
user_profile: UserProfile,
|
|
scheduled_message_id: int,
|
|
lock_message: bool = False,
|
|
) -> ScheduledMessage:
|
|
base_query = ScheduledMessage.objects.all()
|
|
if lock_message:
|
|
# Callers that are going to modify the row should take this lock
|
|
# to avoid racing with an in-progress delivery. Only pass
|
|
# lock_message from within a @transaction.atomic block.
|
|
base_query = base_query.select_for_update(no_key=True)
|
|
try:
|
|
return base_query.get(
|
|
id=scheduled_message_id, sender=user_profile, delivery_type=ScheduledMessage.SEND_LATER
|
|
)
|
|
except ScheduledMessage.DoesNotExist:
|
|
raise ResourceNotFoundError(_("Scheduled message does not exist"))
|
|
|
|
|
|
def get_undelivered_scheduled_messages(
|
|
user_profile: UserProfile,
|
|
) -> list[APIScheduledDirectMessageDict | APIScheduledStreamMessageDict]:
|
|
scheduled_messages = ScheduledMessage.objects.filter(
|
|
realm_id=user_profile.realm_id,
|
|
sender=user_profile,
|
|
# Notably, we don't require failed=False, since we will want
|
|
# to display those to users.
|
|
delivered=False,
|
|
delivery_type=ScheduledMessage.SEND_LATER,
|
|
).order_by("scheduled_timestamp")
|
|
scheduled_message_dicts: list[APIScheduledDirectMessageDict | APIScheduledStreamMessageDict] = [
|
|
scheduled_message.to_dict() for scheduled_message in scheduled_messages
|
|
]
|
|
return scheduled_message_dicts
|
|
|
|
|
|
def get_undelivered_reminders(
|
|
user_profile: UserProfile,
|
|
) -> list[APIReminderDirectMessageDict]:
|
|
reminders = ScheduledMessage.objects.filter(
|
|
realm_id=user_profile.realm_id,
|
|
sender=user_profile,
|
|
# Notably, we don't require failed=False, since we will want
|
|
# to display those to users.
|
|
delivered=False,
|
|
delivery_type=ScheduledMessage.REMIND,
|
|
).order_by("scheduled_timestamp")
|
|
reminder_dicts: list[APIReminderDirectMessageDict] = [
|
|
reminder.to_reminder_dict() for reminder in reminders
|
|
]
|
|
return reminder_dicts
|