Support user devices added or deleted at runtime

This commit is contained in:
miruka 2019-05-09 15:54:31 -04:00
parent d1dfd2673f
commit 4367f52ce5
2 changed files with 43 additions and 2 deletions

View File

@ -32,6 +32,9 @@ class Client(QObject):
messageAboutToBeSent = pyqtSignal(str, dict) messageAboutToBeSent = pyqtSignal(str, dict)
deviceIsPresent = pyqtSignal(str, str, str)
deviceIsDeleted = pyqtSignal(str, str)
def __init__(self, def __init__(self,
manager, manager,
@ -87,7 +90,22 @@ class Client(QObject):
def queryE2EKeys(self) -> None: def queryE2EKeys(self) -> None:
self.net.talk(self.nio.keys_query) print("query")
self._on_query_e2e_keys(self.net.talk(self.nio.keys_query))
def _on_query_e2e_keys(self, response: nio.KeysQueryResponse) -> None:
for user_id, device_dict in response.device_keys.items():
for device_id, payload in device_dict.items():
if device_id == self.nio.device_id:
continue
ed25519_key = payload["keys"][f"ed25519:{device_id}"]
self.deviceIsPresent.emit(user_id, device_id, ed25519_key)
for device_id, device in self.nio.device_store[user_id].items():
if device.deleted:
self.deviceIsDeleted.emit(user_id, device_id)
def claimE2EKeysForRoom(self, room_id: str) -> None: def claimE2EKeysForRoom(self, room_id: str) -> None:
@ -117,7 +135,9 @@ class Client(QObject):
@pyqtSlot(str, str, result="QVariant") @pyqtSlot(str, str, result="QVariant")
@futurize() @futurize()
def login(self, password: str, device_name: str = "") -> "Client": def login(self, password: str, device_name: str = "") -> "Client":
# Main nio client will receive the response here
response = self.net.talk(self.nio.login, password, device_name) response = self.net.talk(self.nio.login, password, device_name)
# Now, receive it with the sync nio client too:
self.nio_sync.receive_response(response) self.nio_sync.receive_response(response)
return self return self

View File

@ -74,7 +74,6 @@ class SignalManager(QObject):
deviceId = dev.id, deviceId = dev.id,
ed25519Key = dev.ed25519, ed25519Key = dev.ed25519,
trust = client.getDeviceTrust(dev), trust = client.getDeviceTrust(dev),
# displayName = TODO
) for dev in store.active_user_devices(user_id) ) for dev in store.active_user_devices(user_id)
]) ])
@ -349,3 +348,25 @@ class SignalManager(QObject):
categ.rooms.pop(room_id, None) categ.rooms.pop(room_id, None)
self.backend.roomEvents[room_id].clear() self.backend.roomEvents[room_id].clear()
def onDeviceIsPresent(self,
client: Client,
user_id: str,
device_id: str,
ed25519_key: str) -> None:
nio_device = client.nio.device_store[user_id][device_id]
self.backend.devices[user_id].upsert(
where_main_key_is = device_id,
update_with = Device(
deviceId = device_id,
ed25519Key = ed25519_key,
trust = client.getDeviceTrust(nio_device),
)
)
def onDeviceIsDeleted(self, _: Client, user_id: str, device_id: str
) -> None:
self.backend.devices[user_id].pop(device_id, None)