message: Refactor send_message_backend to use REQ.

This commit is contained in:
PIG208 2021-07-30 00:08:59 +08:00 committed by Tim Abbott
parent 94685e1afb
commit 15eeb2cb25
2 changed files with 7 additions and 1 deletions

View File

@ -572,6 +572,10 @@ def to_positive_or_allowed_int(allowed_integer: Optional[int] = None) -> Callabl
return converter
def to_float(s: str) -> float:
return float(s)
def to_decimal(s: str) -> Decimal:
return Decimal(s)

View File

@ -23,6 +23,7 @@ from zerver.lib.request import REQ, get_request_notes, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.timestamp import convert_to_UTC
from zerver.lib.topic import REQ_topic
from zerver.lib.validator import to_float
from zerver.lib.zcommand import process_zcommands
from zerver.lib.zephyr import compute_mit_user_fullname
from zerver.models import (
@ -197,6 +198,7 @@ def send_message_backend(
delivery_type: str = REQ("delivery_type", default="send_now", documentation_pending=True),
defer_until: Optional[str] = REQ("deliver_at", default=None, documentation_pending=True),
tz_guess: Optional[str] = REQ("tz_guess", default=None, documentation_pending=True),
time: Optional[float] = REQ(default=None, converter=to_float, documentation_pending=True),
) -> HttpResponse:
# If req_to is None, then we default to an
@ -304,7 +306,7 @@ def send_message_backend(
topic_name,
message_content,
forged=forged,
forged_timestamp=request.POST.get("time"),
forged_timestamp=time,
forwarder_user_profile=user_profile,
realm=realm,
local_id=local_id,