Add JoinRoom page
This commit is contained in:
parent
a9a99e4a65
commit
dbcca17192
|
@ -4,6 +4,7 @@ import html
|
||||||
import io
|
import io
|
||||||
import logging as log
|
import logging as log
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
@ -13,6 +14,7 @@ from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, BinaryIO, DefaultDict, Dict, Optional, Set, Tuple, Type, Union,
|
Any, BinaryIO, DefaultDict, Dict, Optional, Set, Tuple, Type, Union,
|
||||||
)
|
)
|
||||||
|
from urllib.parse import urlparse
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import cairosvg
|
import cairosvg
|
||||||
|
@ -450,6 +452,25 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
return response.room_id
|
return response.room_id
|
||||||
|
|
||||||
|
async def room_join(self, alias_or_id_or_url: str) -> str:
|
||||||
|
string = alias_or_id_or_url.strip()
|
||||||
|
|
||||||
|
if re.match(r"^https?://", string):
|
||||||
|
for part in urlparse(string).fragment.split("/"):
|
||||||
|
if re.match(r"[#!].+:.+", part):
|
||||||
|
string = part
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise ValueError(f"No alias or room id found in url {string}")
|
||||||
|
|
||||||
|
response = await super().join(string)
|
||||||
|
|
||||||
|
if isinstance(response, nio.JoinError):
|
||||||
|
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)
|
||||||
|
|
|
@ -48,7 +48,8 @@ HPage {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
Item {}
|
Item {}
|
||||||
Item {}
|
|
||||||
|
JoinRoom {}
|
||||||
|
|
||||||
CreateRoom {
|
CreateRoom {
|
||||||
id: createRoom
|
id: createRoom
|
||||||
|
|
58
src/qml/Pages/AddChat/JoinRoom.qml
Normal file
58
src/qml/Pages/AddChat/JoinRoom.qml
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Layouts 1.12
|
||||||
|
import "../../Base"
|
||||||
|
import "../../utils.js" as Utils
|
||||||
|
|
||||||
|
HBox {
|
||||||
|
id: addChatBox
|
||||||
|
clickButtonOnEnter: "join"
|
||||||
|
|
||||||
|
onFocusChanged: roomField.forceActiveFocus()
|
||||||
|
|
||||||
|
buttonModel: [
|
||||||
|
{ name: "apply", text: qsTr("Join"), iconName: "apply" },
|
||||||
|
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
||||||
|
]
|
||||||
|
|
||||||
|
buttonCallbacks: ({
|
||||||
|
apply: button => {
|
||||||
|
button.loading = true
|
||||||
|
|
||||||
|
let args = [roomField.text]
|
||||||
|
|
||||||
|
py.callClientCoro(userId, "room_join", args, roomId => {
|
||||||
|
button.loading = false
|
||||||
|
pageLoader.showRoom(userId, roomId)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
cancel: button => {
|
||||||
|
roomField.text = ""
|
||||||
|
pageLoader.showPrevious()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
readonly property string userId: addChatPage.userId
|
||||||
|
|
||||||
|
|
||||||
|
HTextField {
|
||||||
|
id: roomField
|
||||||
|
placeholderText: qsTr("Alias (e.g. #example:matrix.org), URL or ID")
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
HLabel {
|
||||||
|
id: errorMessage
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
color: theme.colors.errorText
|
||||||
|
|
||||||
|
visible: Layout.maximumHeight > 0
|
||||||
|
Layout.maximumHeight: text ? implicitHeight : 0
|
||||||
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user