mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from django.http import HttpRequest, HttpResponse
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from zerver.lib.actions import do_update_pointer
|
|
from zerver.lib.request import REQ, JsonableError, has_request_variables
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.validator import to_non_negative_int
|
|
from zerver.models import UserProfile, get_usermessage_by_message_id
|
|
|
|
|
|
def get_pointer_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
|
return json_success({'pointer': user_profile.pointer})
|
|
|
|
@has_request_variables
|
|
def update_pointer_backend(request: HttpRequest, user_profile: UserProfile,
|
|
pointer: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
|
if pointer <= user_profile.pointer:
|
|
return json_success()
|
|
|
|
if get_usermessage_by_message_id(user_profile, pointer) is None:
|
|
raise JsonableError(_("Invalid message ID"))
|
|
|
|
request._log_data["extra"] = f"[{pointer}]"
|
|
update_flags = (request.client.name.lower() in ['android', "zulipandroid"])
|
|
do_update_pointer(user_profile, request.client, pointer, update_flags=update_flags)
|
|
|
|
return json_success()
|