From 444c357e54c235cc9c16044a44d5d9e0de6d3c90 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 29 Nov 2015 16:39:26 +0100 Subject: [PATCH] dont add local peers to db, just show them in user dialog --- oml/localnodes.py | 13 +++++++------ oml/user/api.py | 8 ++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/oml/localnodes.py b/oml/localnodes.py index 4162e3d..fa6c4a2 100644 --- a/oml/localnodes.py +++ b/oml/localnodes.py @@ -141,12 +141,13 @@ class LocalNodesBase(Thread): if can_connect(data): self._nodes[data['id']] = data with db.session(): - u = user.models.User.get_or_create(data['id']) - u.info['username'] = data['username'] - u.info['local'] = data - u.update_name() - u.save() - state.nodes.queue('add', u.id) + u = user.models.User.get(data['id']) + if u: + u.info['username'] = data['username'] + u.info['local'] = data + u.update_name() + u.save() + state.nodes.queue('add', u.id) self.send() def get_ip(self): diff --git a/oml/user/api.py b/oml/user/api.py index 9049d77..6f9e939 100644 --- a/oml/user/api.py +++ b/oml/user/api.py @@ -83,8 +83,16 @@ def getUsers(data): } ''' users = [] + ids = set() for u in models.User.query.filter(models.User.id!=settings.USER_ID).all(): users.append(u.json()) + ids.add(u.id) + for id in state.nodes._local._nodes: + if id not in ids: + n = state.nodes._local._nodes[id].copy() + n['online'] = True + n['name'] = n['username'] + users.append(n) users.sort(key=lambda u: ox.sort_string(str(u.get('index', '')) + 'Z' + (u.get('name') or ''))) return { "users": users