Implement room creation functions
This commit is contained in:
		@@ -32,6 +32,10 @@ from .pyotherside_events import AlertRequested
 | 
				
			|||||||
CryptDict = Dict[str, Any]
 | 
					CryptDict = Dict[str, Any]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@dataclass
 | 
				
			||||||
 | 
					class RequestFailed(Exception):
 | 
				
			||||||
 | 
					    m_code: Optional[str] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@dataclass
 | 
					@dataclass
 | 
				
			||||||
class UploadError(Exception):
 | 
					class UploadError(Exception):
 | 
				
			||||||
    http_code: Optional[int] = None
 | 
					    http_code: Optional[int] = None
 | 
				
			||||||
@@ -423,6 +427,30 @@ class MatrixClient(nio.AsyncClient):
 | 
				
			|||||||
            more = await self.load_past_events(room_id)
 | 
					            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:
 | 
					    async def room_forget(self, room_id: str) -> None:
 | 
				
			||||||
        await super().room_leave(room_id)
 | 
					        await super().room_leave(room_id)
 | 
				
			||||||
        await super().room_forget(room_id)
 | 
					        await super().room_forget(room_id)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,12 +15,32 @@ HBox {
 | 
				
			|||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    buttonCallbacks: ({
 | 
					    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 {
 | 
					    HRoomAvatar {
 | 
				
			||||||
        // TODO: click to change the avatar
 | 
					        // TODO: click to change the avatar
 | 
				
			||||||
        id: avatar
 | 
					        id: avatar
 | 
				
			||||||
        clientUserId: addChatPage.userId
 | 
					        clientUserId: userId
 | 
				
			||||||
        displayName: nameField.text
 | 
					        displayName: nameField.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Layout.alignment: Qt.AlignCenter
 | 
					        Layout.alignment: Qt.AlignCenter
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user