Implement room creation functions
This commit is contained in:
parent
bfbeb83ce5
commit
ad34d2d171
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user