diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 2878491..21b01c3 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -91,6 +91,8 @@ class ProxyDaemon: database_name = "pan.db" def __attrs_post_init__(self): + loop = asyncio.get_event_loop() + self.homeserver_url = self.homeserver.geturl() self.hostname = self.homeserver.hostname self.store = PanStore(self.data_dir) @@ -130,6 +132,12 @@ class ProxyDaemon: pan_client.load_store() self.pan_clients[user_id] = pan_client + loop.create_task( + self.send_queue.put( + UpdateUsersMessage(self.name, user_id, pan_client.device_id) + ) + ) + pan_client.start_loop() async def _find_client(self, access_token): @@ -542,7 +550,9 @@ class ProxyDaemon: logger.info(f"Succesfully started new background sync client for " f"{user_id}") - await self.send_queue.put(UpdateUsersMessage()) + await self.send_queue.put( + UpdateUsersMessage(self.name, user_id, pan_client.device_id) + ) self.pan_clients[user_id] = pan_client diff --git a/pantalaimon/thread_messages.py b/pantalaimon/thread_messages.py index 2df72b3..d51f0c2 100644 --- a/pantalaimon/thread_messages.py +++ b/pantalaimon/thread_messages.py @@ -54,7 +54,9 @@ class DaemonResponse(Message): @attr.s class UpdateUsersMessage(Message): - pass + server = attr.ib() + user_id = attr.ib() + device_id = attr.ib() @attr.s diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index 054e339..3653b39 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -117,12 +117,10 @@ class Control: self.store = store self.queue = queue self.id_counter = id_counter - self.users = defaultdict(list) - self.update_users() + self.users = defaultdict(set) - def update_users(self): - for server in self.server_list: - self.users[server.name] = self.store.load_users(server.name) + def update_users(self, message): + self.users[message.server].add((message.user_id, message.device_id)) @property def message_id(self): @@ -369,7 +367,6 @@ class GlibT: self.loop = None self.store = PanStore(self.data_dir) - self.users = self.store.load_all_users() id_counter = IdCounter() @@ -489,7 +486,7 @@ class GlibT: self.device_if.update_devices() elif isinstance(message, UpdateUsersMessage): - self.control_if.update_users() + self.control_if.update_users(message) elif isinstance(message, UnverifiedDevicesSignal): self.control_if.UnverifiedDevices(