Exemple #1
0
def 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)),
    notification_to: List[int] = REQ("to", json_validator=check_list(check_int)),
    topic: Optional[str] = REQ("topic", default=None),
) -> HttpResponse:
    to_length = len(notification_to)

    if to_length == 0:
        raise JsonableError(_("Empty 'to' list"))

    if message_type == "stream":
        if to_length > 1:
            raise JsonableError(_("Cannot send to multiple streams"))

        if topic is None:
            raise JsonableError(_("Missing topic"))

        stream_id = notification_to[0]
        # Verify that the user has access to the stream and has
        # permission to send messages to it.
        stream = access_stream_by_id(user_profile, stream_id)[0]
        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 = notification_to
        check_send_typing_notification(user_profile, user_ids, operator)

    return json_success()
Exemple #2
0
def send_notification_backend(
        request: HttpRequest, user_profile: UserProfile,
        operator: str=REQ('op'),
        notification_to: List[str]=REQ('to', converter=extract_recipients, default=[]),
) -> HttpResponse:
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()
Exemple #3
0
def send_notification_backend(
        request: HttpRequest, user_profile: UserProfile,
        operator: Text=REQ('op'),
        notification_to: List[Text]=REQ('to', converter=extract_recipients, default=[]),
) -> HttpResponse:
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()
Exemple #4
0
def send_notification_backend(
    request: HttpRequest,
    user_profile: UserProfile,
    operator: str = REQ("op"),
    notification_to: List[int] = REQ("to", validator=check_list(check_int)),
) -> HttpResponse:
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()
Exemple #5
0
def send_notification_backend(request,
                              user_profile,
                              operator=REQ('op'),
                              notification_to=REQ('to',
                                                  converter=extract_recipients,
                                                  default=[])):
    # type: (HttpRequest, UserProfile, Text, List[Text]) -> HttpResponse
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()
Exemple #6
0
def send_notification_backend(
    request: HttpRequest,
    user_profile: UserProfile,
    operator: str = REQ('op'),
    notification_to: Union[List[str], List[int]] = REQ(
        'to',
        type=Union[List[str], List[int]],
        converter=extract_private_recipients,
        default=[])
) -> HttpResponse:
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()
Exemple #7
0
def send_notification_backend(
    request: HttpRequest,
    user_profile: UserProfile,
    operator: str = REQ("op",
                        str_validator=check_string_in(VALID_OPERATOR_TYPES)),
    user_ids: List[int] = REQ("to", validator=check_list(check_int)),
) -> HttpResponse:
    if len(user_ids) == 0:
        return json_error(_("Missing parameter: 'to' (recipient)"))

    check_send_typing_notification(user_profile, user_ids, operator)
    return json_success()
Exemple #8
0
def send_notification_backend(request, user_profile, operator=REQ('op'),
                              notification_to = REQ('to', converter=extract_recipients, default=[])):
    # type: (HttpRequest, UserProfile, Text, List[Text]) -> HttpResponse
    check_send_typing_notification(user_profile, notification_to, operator)
    return json_success()