mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
scheduled_messages: Migrate to typed_endpoint.
Migrate `scheduled_message.py` to typed_endpoint. Perform Json parsing in the endpoint itself instead of in `recipient_parsing.py`.
This commit is contained in:
committed by
Tim Abbott
parent
7f38c95384
commit
50712bfa81
@@ -1,29 +1,17 @@
|
||||
import orjson
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
|
||||
|
||||
def extract_stream_id(req_to: str) -> int:
|
||||
def extract_stream_id(req_to: int | list[int]) -> int:
|
||||
# Recipient should only be a single stream ID.
|
||||
try:
|
||||
stream_id = int(req_to)
|
||||
except ValueError:
|
||||
if isinstance(req_to, list):
|
||||
raise JsonableError(_("Invalid data type for channel ID"))
|
||||
return stream_id
|
||||
return req_to
|
||||
|
||||
|
||||
def extract_direct_message_recipient_ids(req_to: str) -> list[int]:
|
||||
try:
|
||||
user_ids = orjson.loads(req_to)
|
||||
except orjson.JSONDecodeError:
|
||||
user_ids = req_to
|
||||
|
||||
if not isinstance(user_ids, list):
|
||||
def extract_direct_message_recipient_ids(req_to: int | list[int]) -> list[int]:
|
||||
if not isinstance(req_to, list):
|
||||
raise JsonableError(_("Invalid data type for recipients"))
|
||||
|
||||
for user_id in user_ids:
|
||||
if not isinstance(user_id, int):
|
||||
raise JsonableError(_("Recipient list may only contain user IDs"))
|
||||
|
||||
return list(set(user_ids))
|
||||
return list(set(req_to))
|
||||
|
||||
Reference in New Issue
Block a user