コード例 #1
0
ファイル: django_api.py プロジェクト: yushao2/zulip
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
    if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
        process_notification(data)
    else:
        tornado_uri = get_tornado_uri(realm)
        requests_client().post(
            tornado_uri + "/notify_tornado",
            data=dict(data=orjson.dumps(data), secret=settings.SHARED_SECRET),
        )
コード例 #2
0
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
    if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
        # To allow the backend test suite to not require a separate
        # Tornado process, we simply call the process_notification
        # handler directly rather than making the notify_tornado HTTP
        # request.  It would perhaps be better to instead implement
        # this via some sort of `responses` module configuration, but
        # perhaps it's more readable to have the logic live here.
        #
        # We use an import local to this function to prevent this hack
        # from creating import cycles.
        from zerver.tornado.event_queue import process_notification

        process_notification(data)
    else:
        tornado_uri = get_tornado_uri(realm)
        requests_client().post(
            tornado_uri + "/notify_tornado",
            data=dict(data=orjson.dumps(data), secret=settings.SHARED_SECRET),
        )
コード例 #3
0
ファイル: views.py プロジェクト: zy964c/zulip
def notify(request: HttpRequest) -> HttpResponse:
    process_notification(ujson.loads(request.POST['data']))
    return json_success()
コード例 #4
0
    def test_reformat_legacy_send_message_event(self) -> None:
        hamlet = self.example_user("hamlet")
        cordelia = self.example_user("cordelia")
        othello = self.example_user("othello")
        old_format_event = dict(
            type="message",
            message=1,
            message_dict={},
            presence_idle_user_ids=[hamlet.id, othello.id],
        )
        old_format_users = [
            dict(
                id=hamlet.id,
                flags=["mentioned"],
                mentioned=True,
                online_push_enabled=True,
                stream_push_notify=False,
                stream_email_notify=True,
                wildcard_mention_notify=False,
                sender_is_muted=False,
            ),
            dict(
                id=cordelia.id,
                flags=["wildcard_mentioned"],
                mentioned=False,
                online_push_enabled=True,
                stream_push_notify=True,
                stream_email_notify=False,
                wildcard_mention_notify=True,
                sender_is_muted=False,
            ),
        ]
        notice = dict(event=old_format_event, users=old_format_users)

        expected_current_format_users = [
            dict(
                id=hamlet.id,
                flags=["mentioned"],
            ),
            dict(
                id=cordelia.id,
                flags=["wildcard_mentioned"],
            ),
        ]

        expected_current_format_event = dict(
            type="message",
            message=1,
            message_dict={},
            presence_idle_user_ids=[hamlet.id, othello.id],
            online_push_user_ids=[hamlet.id, cordelia.id],
            stream_push_user_ids=[cordelia.id],
            stream_email_user_ids=[hamlet.id],
            wildcard_mention_user_ids=[cordelia.id],
            muted_sender_user_ids=[],
        )
        with mock.patch("zerver.tornado.event_queue.process_message_event") as m:
            process_notification(notice)
            m.assert_called_once()
            self.assertDictEqual(m.call_args[0][0], expected_current_format_event)
            self.assertEqual(m.call_args[0][1], expected_current_format_users)
コード例 #5
0
ファイル: views.py プロジェクト: 284928489/zulip
def notify(request: HttpRequest) -> HttpResponse:
    process_notification(ujson.loads(request.POST['data']))
    return json_success()
コード例 #6
0
ファイル: views.py プロジェクト: priyank-p/zulip
def notify(request: HttpRequest) -> HttpResponse:
    in_tornado_thread(lambda: process_notification(orjson.loads(request.POST["data"])))
    return json_success(request)