2020-02-28 18:23:57 +01:00
|
|
|
from typing import List
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2021-04-01 17:16:52 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2020-06-11 00:54:34 +02:00
|
|
|
|
|
|
|
from zerver.decorator import REQ, has_request_variables
|
2020-02-28 18:23:57 +01:00
|
|
|
from zerver.lib.actions import check_send_typing_notification
|
2021-04-01 17:16:52 +02:00
|
|
|
from zerver.lib.response import json_error, json_success
|
2021-02-05 19:32:46 +01:00
|
|
|
from zerver.lib.validator import check_int, check_list, check_string_in
|
2016-10-12 20:57:59 +02:00
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
2021-02-05 19:32:46 +01:00
|
|
|
VALID_OPERATOR_TYPES = ["start", "stop"]
|
2021-04-04 12:11:19 +02:00
|
|
|
VALID_MESSAGE_TYPES = ["private"]
|
2021-02-05 19:32:46 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2016-10-12 20:57:59 +02:00
|
|
|
@has_request_variables
|
2017-12-18 15:07:43 +01:00
|
|
|
def send_notification_backend(
|
2021-02-12 08:19:30 +01:00
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
2021-04-04 12:11:19 +02:00
|
|
|
message_type: str = REQ(
|
|
|
|
"type", str_validator=check_string_in(VALID_MESSAGE_TYPES), default="private"
|
|
|
|
),
|
2021-02-05 19:32:46 +01:00
|
|
|
operator: str = REQ("op", str_validator=check_string_in(VALID_OPERATOR_TYPES)),
|
2021-04-01 17:16:52 +02:00
|
|
|
user_ids: List[int] = REQ("to", validator=check_list(check_int)),
|
2021-02-12 08:19:30 +01:00
|
|
|
) -> HttpResponse:
|
2021-04-01 17:16:52 +02:00
|
|
|
if len(user_ids) == 0:
|
|
|
|
return json_error(_("Missing parameter: 'to' (recipient)"))
|
|
|
|
|
|
|
|
check_send_typing_notification(user_profile, user_ids, operator)
|
2016-10-12 20:57:59 +02:00
|
|
|
return json_success()
|