diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 40d30e4e..60728025 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -32,6 +32,10 @@ from .pyotherside_events import AlertRequested CryptDict = Dict[str, Any] +@dataclass +class RequestFailed(Exception): + m_code: Optional[str] = None + @dataclass class UploadError(Exception): http_code: Optional[int] = None @@ -423,6 +427,30 @@ class MatrixClient(nio.AsyncClient): more = await self.load_past_events(room_id) + async def room_create( + self, + name: Optional[str] = None, + topic: Optional[str] = None, + public: bool = False, + encrypt: bool = False, # TODO + federate: bool = True, + ) -> str: + + response = await super().room_create( + name = name, + topic = topic, + federate = federate, + visibility = + nio.RoomVisibility.public if public else + nio.RoomVisibility.private, + ) + + if isinstance(response, nio.RoomCreateError): + raise RequestFailed(response.status_code) + + return response.room_id + + async def room_forget(self, room_id: str) -> None: await super().room_leave(room_id) await super().room_forget(room_id) diff --git a/src/qml/Pages/AddChat/CreateRoom.qml b/src/qml/Pages/AddChat/CreateRoom.qml index 86e3eef3..9ded9e93 100644 --- a/src/qml/Pages/AddChat/CreateRoom.qml +++ b/src/qml/Pages/AddChat/CreateRoom.qml @@ -15,12 +15,32 @@ HBox { ] buttonCallbacks: ({ + apply: button => { + button.loading = true + + let args = [ + nameField.text || null, + topicField.text || null, + publicCheckBox.checked, + encryptCheckBox.checked, + ! blockOtherServersCheckBox.checked, + ] + + py.callClientCoro(userId, "room_create", args, roomId => { + button.loading = false + pageLoader.showRoom(userId, roomId) + }) + }, }) + + readonly property string userId: addChatPage.userId + + HRoomAvatar { // TODO: click to change the avatar id: avatar - clientUserId: addChatPage.userId + clientUserId: userId displayName: nameField.text Layout.alignment: Qt.AlignCenter