Implement device renaming
This commit is contained in:
		| @@ -1258,7 +1258,7 @@ class MatrixClient(nio.AsyncClient): | |||||||
|  |  | ||||||
|  |  | ||||||
|     async def devices_info(self) -> List[Dict[str, Any]]: |     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: |         def get_type(device_id: str) -> str: | ||||||
|             # Return "current", "verified", "blacklisted", "ignored" or "unset" |             # 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 |     # Functions to register/modify data into models | ||||||
|  |  | ||||||
|     async def update_account_unread_counts(self) -> None: |     async def update_account_unread_counts(self) -> None: | ||||||
|   | |||||||
| @@ -12,6 +12,8 @@ HTile { | |||||||
|  |  | ||||||
|     property HListView view |     property HListView view | ||||||
|  |  | ||||||
|  |     signal renameDeviceRequest(string name) | ||||||
|  |  | ||||||
|  |  | ||||||
|     backgroundColor: "transparent" |     backgroundColor: "transparent" | ||||||
|     compact: false |     compact: false | ||||||
| @@ -81,6 +83,7 @@ HTile { | |||||||
|                 width: parent.width |                 width: parent.width | ||||||
|                 defaultText: model.display_name |                 defaultText: model.display_name | ||||||
|                 horizontalAlignment: Qt.AlignHCenter |                 horizontalAlignment: Qt.AlignHCenter | ||||||
|  |                 onAccepted: renameDeviceRequest(text) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 { |     footer: ButtonLayout { | ||||||
|         visible: height >= 0 |         visible: height >= 0 | ||||||
| @@ -67,6 +77,7 @@ HColumnPage { | |||||||
|         delegate: DeviceDelegate { |         delegate: DeviceDelegate { | ||||||
|             width: deviceList.width |             width: deviceList.width | ||||||
|             view: deviceList |             view: deviceList | ||||||
|  |             onRenameDeviceRequest: name => renameDevice(model.index, name) | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         section.property: "type" |         section.property: "type" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	