diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 45481d9a..7ed6e149 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -1258,7 +1258,7 @@ class MatrixClient(nio.AsyncClient): async def devices_info(self) -> List[Dict[str, Any]]: - """Get list of devices and their info for our user.""" + """Get sorted list of devices and their info for our user.""" def get_type(device_id: str) -> str: # Return "current", "verified", "blacklisted", "ignored" or "unset" @@ -1301,6 +1301,16 @@ class MatrixClient(nio.AsyncClient): ) + async def rename_device(self, device_id: str, name: str) -> bool: + """Rename one of our device, return `False` if it doesn't exist.""" + + try: + await self.update_device(device_id, {"display_name": name}) + return True + except MatrixNotFound: + return False + + # Functions to register/modify data into models async def update_account_unread_counts(self) -> None: diff --git a/src/gui/Pages/AccountSettings/DeviceDelegate.qml b/src/gui/Pages/AccountSettings/DeviceDelegate.qml index 1aa4732c..e9f6ad7b 100644 --- a/src/gui/Pages/AccountSettings/DeviceDelegate.qml +++ b/src/gui/Pages/AccountSettings/DeviceDelegate.qml @@ -12,6 +12,8 @@ HTile { property HListView view + signal renameDeviceRequest(string name) + backgroundColor: "transparent" compact: false @@ -81,6 +83,7 @@ HTile { width: parent.width defaultText: model.display_name horizontalAlignment: Qt.AlignHCenter + onAccepted: renameDeviceRequest(text) } } diff --git a/src/gui/Pages/AccountSettings/Sessions.qml b/src/gui/Pages/AccountSettings/Sessions.qml index dd895dec..eafaf12d 100644 --- a/src/gui/Pages/AccountSettings/Sessions.qml +++ b/src/gui/Pages/AccountSettings/Sessions.qml @@ -29,6 +29,16 @@ HColumnPage { }) } + function renameDevice(index, name) { + const device = deviceList.model.get(index) + + device.display_name = name + + py.callClientCoro(userId, "rename_device", [device.id, name], ok => { + if (! ok) deviceList.model.remove(index) // 404 happened + }) + } + footer: ButtonLayout { visible: height >= 0 @@ -67,6 +77,7 @@ HColumnPage { delegate: DeviceDelegate { width: deviceList.width view: deviceList + onRenameDeviceRequest: name => renameDevice(model.index, name) } section.property: "type"