mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
On load, send a range around the pointer, then fill in later, then earlier
This still doesn't handle collapsing entirely correctly for the backfilled messages. (imported from commit d1fa3e2249968208e735454c27b8cab20bb78d3f)
This commit is contained in:
@@ -849,6 +849,13 @@ function add_messages(data) {
|
||||
}
|
||||
});
|
||||
|
||||
// If we prepended messages, then we need to scroll back to the pointer.
|
||||
// This will mess with the user's scrollwheel use; possibly we should be
|
||||
// more clever here. However (for now) we only prepend on page load,
|
||||
// so maybe it's okay.
|
||||
if (data.where === 'top')
|
||||
scroll_to_selected();
|
||||
|
||||
if (autocomplete_needs_update)
|
||||
update_autocomplete();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
||||
from zephyr.forms import RegistrationForm
|
||||
|
||||
from zephyr.decorator import asynchronous
|
||||
from zephyr.lib.query import last_n
|
||||
|
||||
import datetime
|
||||
import simplejson
|
||||
@@ -141,10 +142,11 @@ def update(request):
|
||||
user_profile.save()
|
||||
return json_success()
|
||||
|
||||
def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False):
|
||||
def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False, where='bottom'):
|
||||
if mit_sync_bot:
|
||||
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],
|
||||
'where': where}
|
||||
|
||||
def return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||
try:
|
||||
@@ -155,11 +157,24 @@ def return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
messages = (Zephyr.objects.filter(usermessage__user_profile = user_profile,
|
||||
id__gt = last)
|
||||
.order_by('id')[:400])
|
||||
where = 'bottom'
|
||||
query = Zephyr.objects.filter(usermessage__user_profile = user_profile).order_by('id')
|
||||
|
||||
if last == -1:
|
||||
# User has no messages yet
|
||||
# Get a range around the pointer
|
||||
ptr = user_profile.pointer
|
||||
messages = (last_n(200, query.filter(id__lt=ptr))
|
||||
+ list(query.filter(id__gte=ptr)[:200]))
|
||||
else:
|
||||
messages = query.filter(id__gt=last)[:400]
|
||||
if not messages:
|
||||
# No more messages in the future; try filling in from the past.
|
||||
messages = last_n(400, query.filter(id__lt=first))
|
||||
where = 'top'
|
||||
|
||||
if messages:
|
||||
handler.finish(format_updates_response(messages, **kwargs))
|
||||
handler.finish(format_updates_response(messages, where=where, **kwargs))
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user