2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-11-10 00:52:16 +11:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../../Base"
|
|
|
|
|
|
|
|
HBox {
|
|
|
|
id: addChatBox
|
2019-11-10 02:18:36 +11:00
|
|
|
clickButtonOnEnter: "apply"
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
onFocusChanged: roomField.forceActiveFocus()
|
|
|
|
|
|
|
|
buttonModel: [
|
2019-12-08 00:38:36 +11:00
|
|
|
{
|
|
|
|
name: "apply",
|
|
|
|
text: qsTr("Join"),
|
2019-12-13 23:30:36 +11:00
|
|
|
iconName: "room-join",
|
2019-12-12 03:46:43 +11:00
|
|
|
enabled: Boolean(roomField.text.trim()),
|
2019-12-08 00:38:36 +11:00
|
|
|
},
|
2019-11-10 00:52:16 +11:00
|
|
|
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
|
|
|
]
|
|
|
|
|
|
|
|
buttonCallbacks: ({
|
|
|
|
apply: button => {
|
2019-11-10 02:15:24 +11:00
|
|
|
button.loading = true
|
|
|
|
errorMessage.text = ""
|
2019-11-10 00:52:16 +11:00
|
|
|
|
2019-12-12 03:46:43 +11:00
|
|
|
let args = [roomField.text.trim()]
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
py.callClientCoro(userId, "room_join", args, roomId => {
|
2019-11-10 01:20:16 +11:00
|
|
|
button.loading = false
|
|
|
|
errorMessage.text = ""
|
2019-11-10 00:52:16 +11:00
|
|
|
pageLoader.showRoom(userId, roomId)
|
2019-11-10 01:20:16 +11:00
|
|
|
|
|
|
|
}, (type, args) => {
|
|
|
|
button.loading = false
|
|
|
|
|
2019-11-10 05:20:53 +11:00
|
|
|
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
|
2019-11-10 01:20:16 +11:00
|
|
|
|
|
|
|
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 => {
|
2019-11-10 01:20:16 +11:00
|
|
|
roomField.text = ""
|
|
|
|
errorMessage.text = ""
|
2019-11-10 00:52:16 +11:00
|
|
|
pageLoader.showPrevious()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
readonly property string userId: addChatPage.userId
|
|
|
|
|
|
|
|
|
2019-11-10 06:19:10 +11:00
|
|
|
CurrentUserAvatar {
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
Layout.preferredWidth: 128
|
|
|
|
Layout.preferredHeight: Layout.preferredWidth
|
|
|
|
}
|
|
|
|
|
2019-11-10 00:52:16 +11:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|