Split out do_update_pointer from update_pointer_backend.

(imported from commit 25da1b324a9170677b0f6fc2e29841d6f2af9dec)
This commit is contained in:
Tim Abbott
2014-01-24 17:50:24 -05:00
parent 5ccb8b1bea
commit 0507b1bb06
2 changed files with 24 additions and 20 deletions

View File

@@ -1482,6 +1482,27 @@ def update_user_presence(user_profile, client, log_time, status,
if new_user_input:
update_user_activity_interval(user_profile, log_time)
def do_update_pointer(user_profile, pointer, update_flags=False):
prev_pointer = user_profile.pointer
user_profile.pointer = pointer
user_profile.save(update_fields=["pointer"])
if update_flags:
# Until we handle the new read counts in the Android app
# natively, this is a shim that will mark as read any messages
# up until the pointer move
UserMessage.objects.filter(user_profile=user_profile,
message__id__gt=prev_pointer,
message__id__lte=pointer,
flags=~UserMessage.flags.read) \
.update(flags=F('flags').bitor(UserMessage.flags.read))
if settings.TORNADO_SERVER:
tornado_callbacks.send_notification(dict(
type = 'pointer_update',
user = user_profile.id,
new_pointer = pointer))
def do_update_message_flags(user_profile, operation, flag, messages, all):
flagattr = getattr(UserMessage.flags, flag)

View File

@@ -38,7 +38,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, do_change_password, \
notify_for_streams_by_default, do_change_enable_offline_push_notifications, \
do_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public, \
do_make_stream_private, do_change_default_desktop_notifications, \
do_change_stream_description
do_change_stream_description, do_update_pointer
from zerver.lib.create_user import random_api_key
from zerver.lib.push_notifications import num_push_devices_for_user
from zerver.forms import RegistrationForm, HomepageForm, ToSForm, \
@@ -957,26 +957,9 @@ def update_pointer_backend(request, user_profile,
except UserMessage.DoesNotExist:
raise JsonableError("Invalid message ID")
prev_pointer = user_profile.pointer
user_profile.pointer = pointer
user_profile.save(update_fields=["pointer"])
request._log_data["extra"] = "[%s]" % (pointer,)
if request.client.name.lower() in ['android', "zulipandroid"]:
# Until we handle the new read counts in the Android app
# natively, this is a shim that will mark as read any messages
# up until the pointer move
UserMessage.objects.filter(user_profile=user_profile,
message__id__gt=prev_pointer,
message__id__lte=pointer,
flags=~UserMessage.flags.read) \
.update(flags=F('flags').bitor(UserMessage.flags.read))
if settings.TORNADO_SERVER:
tornado_callbacks.send_notification(dict(
type = 'pointer_update',
user = user_profile.id,
new_pointer = pointer))
update_flags = (request.client.name.lower() in ['android', "zulipandroid"])
do_update_pointer(user_profile, pointer, update_flags=update_flags)
return json_success()