diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 7a630f3..b5325fa 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -56,9 +56,9 @@ class ProxyDaemon: self.homeserver_url = self.homeserver.geturl() self.hostname = self.homeserver.hostname self.store = PanStore(self.data_dir) - accounts = self.store.load_users(self.hostname) + accounts = self.store.load_users(self.name) - self.client_info = self.store.load_clients(self.hostname) + self.client_info = self.store.load_clients(self.name) for user_id, device_id in accounts: token = keyring.get_password( @@ -421,8 +421,8 @@ class ProxyDaemon: async def start_pan_client(self, access_token, user, user_id, password): client = ClientInfo(user_id, access_token) self.client_info[access_token] = client - self.store.save_client(self.hostname, client) - self.store.save_server_user(self.hostname, user_id) + self.store.save_client(self.name, client) + self.store.save_server_user(self.name, user_id) if user_id in self.pan_clients: logger.info(f"Background sync client already exists for {user_id}," diff --git a/pantalaimon/store.py b/pantalaimon/store.py index 338e91f..32654fd 100644 --- a/pantalaimon/store.py +++ b/pantalaimon/store.py @@ -20,10 +20,10 @@ class AccessTokens(Model): class Servers(Model): - hostname = TextField() + name = TextField() class Meta: - constraints = [SQL("UNIQUE(hostname)")] + constraints = [SQL("UNIQUE(name)")] class ServerUsers(Model): @@ -116,9 +116,9 @@ class PanStore: return None @use_database - def save_server_user(self, homeserver, user_id): + def save_server_user(self, server_name, user_id): # type: (ClientInfo) -> None - server, _ = Servers.get_or_create(hostname=homeserver) + server, _ = Servers.get_or_create(name=server_name) ServerUsers.replace( user_id=user_id, @@ -140,11 +140,11 @@ class PanStore: return users @use_database - def load_users(self, homeserver): + def load_users(self, server_name): # type: () -> List[Tuple[str, str]] users = [] - server = Servers.get_or_none(Servers.hostname == homeserver) + server = Servers.get_or_none(Servers.name == server_name) if not server: return [] @@ -188,9 +188,9 @@ class PanStore: return None @use_database - def save_client(self, homeserver, client): + def save_client(self, server_name, client): # type: (ClientInfo) -> None - server, _ = Servers.get_or_create(hostname=homeserver) + server, _ = Servers.get_or_create(name=server_name) Clients.replace( user_id=client.user_id, @@ -199,11 +199,11 @@ class PanStore: ).execute() @use_database - def load_clients(self, homeserver): + def load_clients(self, server_name): # type: () -> Dict[str, ClientInfo] clients = dict() - server, _ = Servers.get_or_create(hostname=homeserver) + server, _ = Servers.get_or_create(name=server_name) for c in server.clients: client = ClientInfo(c.user_id, c.token) diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index 0fcbc7e..b3732ff 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -76,9 +76,7 @@ class Control: def update_users(self): for server in self.server_list: - self.users[server.name] = self.store.load_users( - server.homeserver.hostname - ) + self.users[server.name] = self.store.load_users(server.name) @property def message_id(self):