2016-09-14 02:20:36 +02:00
|
|
|
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 has_request_variables, JsonableError, REQ
|
|
|
|
from zerver.lib.response import json_success
|
2020-05-07 13:19:54 +02:00
|
|
|
from zerver.lib.validator import to_non_negative_int
|
2019-02-02 23:53:22 +01:00
|
|
|
from zerver.models import UserProfile, get_usermessage_by_message_id
|
2016-09-14 02:20:36 +02:00
|
|
|
|
2017-10-27 02:18:49 +02:00
|
|
|
def get_pointer_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
2016-09-14 02:20:36 +02:00
|
|
|
return json_success({'pointer': user_profile.pointer})
|
|
|
|
|
|
|
|
@has_request_variables
|
2017-12-09 06:40:51 +01:00
|
|
|
def update_pointer_backend(request: HttpRequest, user_profile: UserProfile,
|
|
|
|
pointer: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
2016-09-14 02:20:36 +02:00
|
|
|
if pointer <= user_profile.pointer:
|
|
|
|
return json_success()
|
|
|
|
|
2018-07-27 11:47:07 +02:00
|
|
|
if get_usermessage_by_message_id(user_profile, pointer) is None:
|
2016-09-14 02:20:36 +02:00
|
|
|
raise JsonableError(_("Invalid message ID"))
|
|
|
|
|
|
|
|
request._log_data["extra"] = "[%s]" % (pointer,)
|
|
|
|
update_flags = (request.client.name.lower() in ['android', "zulipandroid"])
|
2018-03-14 00:01:04 +01:00
|
|
|
do_update_pointer(user_profile, request.client, pointer, update_flags=update_flags)
|
2016-09-14 02:20:36 +02:00
|
|
|
|
|
|
|
return json_success()
|