moment/src/gui/Pages/AddChat/DirectChat.qml

125 lines
3.0 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
2019-11-10 05:20:53 +11:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../.."
2019-11-10 05:20:53 +11:00
import "../../Base"
import "../../Base/ButtonLayout"
2019-11-10 05:20:53 +11:00
HFlickableColumnPage {
id: page
2019-11-10 05:20:53 +11:00
property string userId
readonly property QtObject account: ModelStore.get("accounts").find(userId)
2019-11-10 05:20:53 +11:00
function takeFocus() {
userField.item.forceActiveFocus()
}
2019-11-10 05:20:53 +11:00
function startChat() {
applyButton.loading = true
errorMessage.text = ""
2019-11-10 05:20:53 +11:00
const args = [userField.item.text.trim(), encryptCheckBox.checked]
2019-11-10 05:20:53 +11:00
py.callClientCoro(userId, "new_direct_chat", args, roomId => {
applyButton.loading = false
errorMessage.text = ""
pageLoader.showRoom(userId, roomId)
mainPane.roomList.startCorrectItemSearch()
2019-11-10 05:20:53 +11:00
}, (type, args) => {
applyButton.loading = false
2019-11-10 05:20:53 +11:00
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
2019-12-05 00:59:14 +11:00
if (type === "InvalidUserInContext")
txt = qsTr("Can't start chatting with yourself")
2019-11-10 05:20:53 +11:00
if (type === "InvalidUserId")
txt = qsTr("Invalid user ID, expected format is " +
"@username:homeserver")
if (type === "MatrixNotFound")
txt = qsTr("User not found, please verify the entered ID")
2019-11-10 05:20:53 +11:00
if (type === "MatrixBadGateway")
txt = qsTr(
"Could not contact this user's server, " +
"please verify the entered ID"
)
errorMessage.text = txt
})
}
function cancel() {
userField.item.reset()
errorMessage.text = ""
pageLoader.showPrevious()
}
footer: ButtonLayout {
ApplyButton {
id: applyButton
text: qsTr("Start chat")
icon.name: "start-direct-chat"
enabled: Boolean(userField.item.text.trim())
onClicked: startChat()
2019-11-10 05:20:53 +11:00
}
CancelButton {
onClicked: {
userField.item.text = ""
errorMessage.text = ""
pageLoader.showPrevious()
}
}
}
2019-11-10 05:20:53 +11:00
onKeyboardAccept: startChat()
onKeyboardCancel: cancel()
2019-11-10 05:20:53 +11:00
2019-11-10 06:19:10 +11:00
CurrentUserAvatar {
userId: page.userId
account: page.account
2019-11-10 06:19:10 +11:00
}
HLabeledItem {
2019-11-10 05:20:53 +11:00
id: userField
2020-03-18 04:40:58 +11:00
label.text: qsTr("Peer user ID:")
2019-11-10 05:20:53 +11:00
Layout.fillWidth: true
HTextField {
width: parent.width
placeholderText: qsTr("@example:matrix.org")
error: Boolean(errorMessage.text)
}
2019-11-10 05:20:53 +11:00
}
EncryptCheckBox {
id: encryptCheckBox
Layout.fillWidth: true
}
2019-11-10 05:20:53 +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
}
}