mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
Move the code for new messages immediately available into views.py
(imported from commit 4cfa0ead850b1a37a21ec7945b477e12681c5830)
This commit is contained in:
parent
946c901e05
commit
a8ec5c533f
@ -85,16 +85,8 @@ class UserProfile(models.Model):
|
||||
|
||||
callback_table[self.user.id] = []
|
||||
|
||||
def add_callback(self, cb, last_received=None):
|
||||
def add_callback(self, cb):
|
||||
global callback_table
|
||||
|
||||
if last_received:
|
||||
new_zephyrs = (Zephyr.objects.filter(usermessage__user_profile = self,
|
||||
id__gt = last_received)
|
||||
.order_by('id')[:400])
|
||||
if new_zephyrs:
|
||||
return cb(new_zephyrs)
|
||||
|
||||
callback_table.setdefault(self.user.id, []).append(cb)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@ -148,6 +148,15 @@ def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False):
|
||||
|
||||
def get_updates_backend(request, handler, last_received=None, **kwargs):
|
||||
user_profile = UserProfile.objects.get(user=request.user)
|
||||
|
||||
if last_received:
|
||||
new_messages = (Zephyr.objects.filter(usermessage__user_profile = user_profile,
|
||||
id__gt = last_received)
|
||||
.order_by('id')[:400])
|
||||
if new_messages:
|
||||
handler.finish(format_updates_response(new_messages, **kwargs))
|
||||
return
|
||||
|
||||
def on_receive(zephyrs):
|
||||
if handler.request.connection.stream.closed():
|
||||
return
|
||||
@ -156,7 +165,7 @@ def get_updates_backend(request, handler, last_received=None, **kwargs):
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
user_profile.add_callback(handler.async_callback(on_receive), last_received)
|
||||
user_profile.add_callback(handler.async_callback(on_receive))
|
||||
|
||||
@login_required
|
||||
@asynchronous
|
||||
|
||||
Loading…
Reference in New Issue
Block a user