2016-09-14 02:20:36 +02:00
|
|
|
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from django.utils.translation import ugettext as _
|
2016-12-25 00:44:26 +01:00
|
|
|
from typing import Text
|
2016-09-14 02:20:36 +02:00
|
|
|
|
|
|
|
from zerver.decorator import to_non_negative_int
|
|
|
|
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
|
2016-12-15 12:22:24 +01:00
|
|
|
from zerver.models import UserProfile, UserMessage
|
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
|
|
|
|
def update_pointer_backend(request, user_profile,
|
|
|
|
pointer=REQ(converter=to_non_negative_int)):
|
|
|
|
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
|
|
|
if pointer <= user_profile.pointer:
|
|
|
|
return json_success()
|
|
|
|
|
|
|
|
try:
|
|
|
|
UserMessage.objects.get(
|
|
|
|
user_profile=user_profile,
|
|
|
|
message__id=pointer
|
|
|
|
)
|
|
|
|
except UserMessage.DoesNotExist:
|
|
|
|
raise JsonableError(_("Invalid message ID"))
|
|
|
|
|
|
|
|
request._log_data["extra"] = "[%s]" % (pointer,)
|
|
|
|
update_flags = (request.client.name.lower() in ['android', "zulipandroid"])
|
|
|
|
do_update_pointer(user_profile, pointer, update_flags=update_flags)
|
|
|
|
|
|
|
|
return json_success()
|