def load_all_devices(self): # type (str, str) -> Dict[str, Dict[str, DeviceStore]] store = dict() query = Accounts.select() for account in query: device_store = defaultdict(dict) for d in account.device_keys: if d.deleted: continue try: trust_state = d.trust_state[0].state except IndexError: trust_state = TrustState.unset keys = {k.key_type: k.key for k in d.keys} device_store[d.user_id][d.device_id] = { "user_id": d.user_id, "device_id": d.device_id, "ed25519": keys["ed25519"], "curve25519": keys["curve25519"], "trust_state": trust_state.name, "device_display_name": d.display_name, } store[account.user_id] = device_store return store
def load_all_users(self): users = [] query = Accounts.select(Accounts.user_id, Accounts.device_id) for account in query: users.append((account.user_id, account.device_id)) return users
def load_users(self, server_name): # type: (str) -> List[Tuple[str, str]] users = [] server = Servers.get_or_none(Servers.name == server_name) if not server: return [] server_users = [] for u in server.users: server_users.append(u.user_id) query = Accounts.select(Accounts.user_id, Accounts.device_id).where( Accounts.user_id.in_(server_users)) for account in query: users.append((account.user_id, account.device_id)) return users