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)
|
if (autocomplete_needs_update)
|
||||||
update_autocomplete();
|
update_autocomplete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
|||||||
from zephyr.forms import RegistrationForm
|
from zephyr.forms import RegistrationForm
|
||||||
|
|
||||||
from zephyr.decorator import asynchronous
|
from zephyr.decorator import asynchronous
|
||||||
|
from zephyr.lib.query import last_n
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import simplejson
|
import simplejson
|
||||||
@@ -141,10 +142,11 @@ def update(request):
|
|||||||
user_profile.save()
|
user_profile.save()
|
||||||
return json_success()
|
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:
|
if mit_sync_bot:
|
||||||
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],
|
||||||
|
'where': where}
|
||||||
|
|
||||||
def return_messages_immediately(request, handler, user_profile, **kwargs):
|
def return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||||
try:
|
try:
|
||||||
@@ -155,11 +157,24 @@ def return_messages_immediately(request, handler, user_profile, **kwargs):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
messages = (Zephyr.objects.filter(usermessage__user_profile = user_profile,
|
where = 'bottom'
|
||||||
id__gt = last)
|
query = Zephyr.objects.filter(usermessage__user_profile = user_profile).order_by('id')
|
||||||
.order_by('id')[:400])
|
|
||||||
|
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:
|
if messages:
|
||||||
handler.finish(format_updates_response(messages, **kwargs))
|
handler.finish(format_updates_response(messages, where=where, **kwargs))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user