Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Refactor view to support message_type.
Dineshcd62b40f2083
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 465a5ea295c..d284f65be2d 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -9220,6 +9220,15 @@ paths:[the typing notification docs](https://zulip.readthedocs.io/en/latest/subsystems/typing-indicators.html)for additional design details on Zulip's typing notifications protocol.parameters:+ - name: type+ in: query+ description: |+ Type of the message being composed.+ schema:+ type: string+ enum:+ - private+ default: private- name: opin: querydescription: |diff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.pyindex da20b73803e..ab3fce57a11 100644--- a/zerver/tests/test_typing.py+++ b/zerver/tests/test_typing.py@@ -32,6 +32,18 @@ class TypingValidateOperatorTest(ZulipTestCase):self.assert_json_error(result, "Invalid op")+class TypingMessagetypeTest(ZulipTestCase):+ def test_invalid_type(self) -> None:+ sender = self.example_user("hamlet")+ params = dict(+ to=orjson.dumps([sender.id]).decode(),+ type="invalid",+ op="start",+ )+ result = self.api_post(sender, "/api/v1/typing", params)+ self.assert_json_error(result, "Invalid type")++class TypingValidateUsersTest(ZulipTestCase):def test_empty_array(self) -> None:"""diff --git a/zerver/views/typing.py b/zerver/views/typing.pyindex a239375458e..33ac880c617 100644--- a/zerver/views/typing.py+++ b/zerver/views/typing.py@@ -10,12 +10,16 @@ from zerver.lib.validator import check_int, check_list, check_string_infrom zerver.models import UserProfileVALID_OPERATOR_TYPES = ["start", "stop"]+VALID_MESSAGE_TYPES = ["private"]@has_request_variablesdef send_notification_backend(request: HttpRequest,user_profile: UserProfile,+ message_type: str = REQ(+ "type", str_validator=check_string_in(VALID_MESSAGE_TYPES), default="private"+ ),operator: str = REQ("op", str_validator=check_string_in(VALID_OPERATOR_TYPES)),user_ids: List[int] = REQ("to", validator=check_list(check_int)),) -> HttpResponse: