mirror of
https://github.com/zulip/zulip.git
synced 2025-10-28 18:43:52 +00:00
typing_indicator: Add a 'stream_id' parameter to 'POST /typing'.
This commit adds a 'stream_id' parameter to the 'POST /typing' endpoint. Now, 'to' is used only for "direct" type. In the case of "stream" type, 'stream_id' and 'topic' are used.
This commit is contained in:
committed by
Tim Abbott
parent
78683c1b9c
commit
c520a96354
@@ -1,15 +1,14 @@
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from zerver.actions.typing import check_send_typing_notification, do_send_stream_typing_notification
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.streams import access_stream_by_id, access_stream_for_send_message
|
||||
from zerver.lib.validator import check_string_in
|
||||
from zerver.lib.validator import check_int, check_list, check_string_in
|
||||
from zerver.models import UserProfile
|
||||
|
||||
VALID_OPERATOR_TYPES = ["start", "stop"]
|
||||
@@ -24,12 +23,17 @@ def send_notification_backend(
|
||||
"type", str_validator=check_string_in(VALID_RECIPIENT_TYPES), default="direct"
|
||||
),
|
||||
operator: str = REQ("op", str_validator=check_string_in(VALID_OPERATOR_TYPES)),
|
||||
notification_to: str = REQ("to"),
|
||||
notification_to: Optional[List[int]] = REQ(
|
||||
"to", json_validator=check_list(check_int), default=None
|
||||
),
|
||||
stream_id: Optional[int] = REQ(json_validator=check_int, default=None),
|
||||
topic: Optional[str] = REQ("topic", default=None),
|
||||
) -> HttpResponse:
|
||||
recipient_type_name = req_type
|
||||
if recipient_type_name == "stream":
|
||||
stream_id = extract_stream_id(notification_to)
|
||||
if stream_id is None:
|
||||
raise JsonableError(_("Missing stream_id"))
|
||||
|
||||
if topic is None:
|
||||
raise JsonableError(_("Missing topic"))
|
||||
|
||||
@@ -42,7 +46,10 @@ def send_notification_backend(
|
||||
access_stream_for_send_message(user_profile, stream, forwarder_user_profile=None)
|
||||
do_send_stream_typing_notification(user_profile, operator, stream, topic)
|
||||
else:
|
||||
user_ids = extract_direct_message_recipient_ids(notification_to)
|
||||
if notification_to is None:
|
||||
raise JsonableError(_("Missing 'to' argument"))
|
||||
|
||||
user_ids = notification_to
|
||||
to_length = len(user_ids)
|
||||
if to_length == 0:
|
||||
raise JsonableError(_("Empty 'to' list"))
|
||||
|
||||
Reference in New Issue
Block a user