moment/src/qml/Pages/AddChat/JoinRoom.qml

80 lines
2.1 KiB
QML
Raw Normal View History

2019-11-10 00:52:16 +11:00
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: [
2019-11-10 02:10:00 +11:00
{ name: "apply", text: qsTr("Join"), iconName: "join",
enabled: Boolean(roomField.text), },
2019-11-10 00:52:16 +11:00
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
buttonCallbacks: ({
apply: button => {
button.loading = true
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
let args = [roomField.text]
py.callClientCoro(userId, "room_join", args, roomId => {
button.loading = false
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
pageLoader.showRoom(userId, roomId)
}, (type, args) => {
button.loading = false
let txt = qsTr("Unknown error - %1, %2").arg(type).arg(args)
if (type === "ValueError")
txt = qsTr("Unrecognized alias, room ID or URL")
if (type === "MatrixNotFound")
txt = qsTr("Room not found")
if (type === "MatrixForbidden")
txt = qsTr("You do not have permission to join this room")
errorMessage.text = txt
2019-11-10 00:52:16 +11:00
})
},
cancel: button => {
roomField.text = ""
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
pageLoader.showPrevious()
}
})
readonly property string userId: addChatPage.userId
HTextField {
id: roomField
placeholderText: qsTr("Alias (e.g. #example:matrix.org), URL or ID")
2019-11-10 01:34:54 +11:00
error: Boolean(errorMessage.text)
2019-11-10 00:52:16 +11:00
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
}
}