diff --git a/oml/user/models.py b/oml/user/models.py index d9e715b..1daa527 100644 --- a/oml/user/models.py +++ b/oml/user/models.py @@ -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_')] diff --git a/oml/websocket.py b/oml/websocket.py index 734780a..206cc75 100644 --- a/oml/websocket.py +++ b/oml/websocket.py @@ -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):