trigger status for all peers on ws connect

This commit is contained in:
j 2016-01-31 22:14:00 +05:30
parent 2c61fcc111
commit 0cc3a4523e
2 changed files with 9 additions and 3 deletions

View file

@ -109,6 +109,12 @@ class User(db.Model):
def is_online(self):
return state.nodes and state.nodes.is_online(self.id)
def trigger_status(self):
trigger_event('status', {
'id': self.id,
'online': self.is_online()
})
def lists_json(self):
self.library
return [l.json() for l in self.lists.order_by('index_')]

View file

@ -37,13 +37,13 @@ class Handler(WebSocketHandler):
if state.update:
trigger_event('updatestatus', state.tasks._status)
else:
from user.models import User
trigger_event('status', {
'id': settings.USER_ID,
'online': state.online
})
if state.nodes:
for node in state.nodes._nodes.values():
node.trigger_status()
for u in User.query.filter(User.id!=settings.USER_ID).filter_by(peered=True).all():
u.trigger_status()
#websocket calls
def on_message(self, message):