mirror of https://github.com/zulip/zulip.git
Factor out the determination of which messages to send immediately
(imported from commit 31c688986e4d8f923913083f36dea9c79a4c36ce)
This commit is contained in:
parent
a8ec5c533f
commit
c65a387c1e
|
@ -146,15 +146,27 @@ def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False):
|
||||||
messages = [m for m in messages if not mit_sync_table.get(m.id)]
|
messages = [m for m in messages if not mit_sync_table.get(m.id)]
|
||||||
return {'zephyrs': [message.to_dict(apply_markdown) for message in messages]}
|
return {'zephyrs': [message.to_dict(apply_markdown) for message in messages]}
|
||||||
|
|
||||||
def get_updates_backend(request, handler, last_received=None, **kwargs):
|
def return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||||
user_profile = UserProfile.objects.get(user=request.user)
|
try:
|
||||||
|
first = int(request.POST['first'])
|
||||||
|
last = int(request.POST['last'])
|
||||||
|
except TypeError:
|
||||||
|
return False
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
if last_received:
|
messages = (Zephyr.objects.filter(usermessage__user_profile = user_profile,
|
||||||
new_messages = (Zephyr.objects.filter(usermessage__user_profile = user_profile,
|
id__gt = last)
|
||||||
id__gt = last_received)
|
|
||||||
.order_by('id')[:400])
|
.order_by('id')[:400])
|
||||||
if new_messages:
|
if messages:
|
||||||
handler.finish(format_updates_response(new_messages, **kwargs))
|
handler.finish(format_updates_response(messages, **kwargs))
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_updates_backend(request, handler, **kwargs):
|
||||||
|
user_profile = UserProfile.objects.get(user=request.user)
|
||||||
|
if return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_receive(zephyrs):
|
def on_receive(zephyrs):
|
||||||
|
@ -171,11 +183,9 @@ def get_updates_backend(request, handler, last_received=None, **kwargs):
|
||||||
@asynchronous
|
@asynchronous
|
||||||
@require_post
|
@require_post
|
||||||
def get_updates(request, handler):
|
def get_updates(request, handler):
|
||||||
last_received = request.POST.get('last')
|
if not ('last' in request.POST and 'first' in request.POST):
|
||||||
if not last_received:
|
return json_error("Missing message range")
|
||||||
return json_error("Missing last received")
|
return get_updates_backend(request, handler, apply_markdown=True)
|
||||||
return get_updates_backend(request, handler, last_received=last_received,
|
|
||||||
apply_markdown=True)
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@asynchronous
|
@asynchronous
|
||||||
|
|
Loading…
Reference in New Issue