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
|
2020-06-25 22:32:08 +10:00
|
|
|
import "../.."
|
2019-11-10 00:52:16 +11:00
|
|
|
import "../../Base"
|
2020-06-25 22:32:08 +10:00
|
|
|
import "../../Base/ButtonLayout"
|
2019-11-10 00:52:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
HFlickableColumnPage {
|
|
|
|
id: page
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
property string userId
|
|
|
|
readonly property QtObject account: ModelStore.get("accounts").find(userId)
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
function takeFocus() {
|
|
|
|
roomField.item.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
function join() {
|
|
|
|
joinButton.loading = true
|
|
|
|
errorMessage.text = ""
|
|
|
|
|
|
|
|
const args = [roomField.item.text.trim()]
|
|
|
|
|
|
|
|
py.callClientCoro(userId, "room_join", args, roomId => {
|
|
|
|
joinButton.loading = false
|
|
|
|
errorMessage.text = ""
|
|
|
|
pageLoader.showRoom(userId, roomId)
|
|
|
|
mainPane.roomList.startCorrectItemSearch()
|
|
|
|
|
|
|
|
}, (type, args) => {
|
|
|
|
joinButton.loading = false
|
2019-11-10 00:52:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "ValueError")
|
|
|
|
txt = qsTr("Unrecognized alias, room ID or URL")
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "MatrixNotFound")
|
|
|
|
txt = qsTr("Room not found")
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "MatrixForbidden")
|
|
|
|
txt = qsTr("You do not have permission to join this room")
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
errorMessage.text = txt
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel() {
|
|
|
|
roomField.item.reset()
|
|
|
|
errorMessage.reset()
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
pageLoader.showPrevious()
|
|
|
|
}
|
2019-11-10 01:20:16 +11:00
|
|
|
|
2019-11-10 00:52:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
footer: ButtonLayout {
|
|
|
|
ApplyButton {
|
|
|
|
text: qsTr("Join")
|
|
|
|
icon.name: "room-join"
|
|
|
|
enabled: Boolean(roomField.item.text.trim())
|
|
|
|
onClicked: join()
|
2019-11-10 00:52:16 +11:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
CancelButton {
|
|
|
|
onClicked: cancel()
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 00:52:16 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
Keys.onEscapePressed: cancel()
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
|
2019-11-10 06:19:10 +11:00
|
|
|
CurrentUserAvatar {
|
2020-06-25 22:32:08 +10:00
|
|
|
userId: page.userId
|
|
|
|
account: page.account
|
2019-11-10 06:19:10 +11:00
|
|
|
}
|
|
|
|
|
2020-06-03 10:14:55 +10:00
|
|
|
HLabeledItem {
|
2019-11-10 00:52:16 +11:00
|
|
|
id: roomField
|
2020-03-18 04:40:58 +11:00
|
|
|
label.text: qsTr("Alias, URL or room ID:")
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2020-06-03 10:14:55 +10:00
|
|
|
|
|
|
|
HTextField {
|
|
|
|
width: parent.width
|
|
|
|
placeholderText: qsTr("#example:matrix.org")
|
|
|
|
error: Boolean(errorMessage.text)
|
|
|
|
}
|
2019-11-10 00:52:16 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|