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
|
2020-06-25 22:32:08 +10:00
|
|
|
import "../.."
|
2019-11-10 05:20:53 +11:00
|
|
|
import "../../Base"
|
2020-07-12 12:52:14 +10:00
|
|
|
import "../../Base/Buttons"
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
HFlickableColumnPage {
|
|
|
|
id: page
|
2019-11-10 05:20:53 +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 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
function takeFocus() {
|
|
|
|
userField.item.forceActiveFocus()
|
|
|
|
}
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
function startChat() {
|
|
|
|
applyButton.loading = true
|
|
|
|
errorMessage.text = ""
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
const args = [userField.item.text.trim(), encryptCheckBox.checked]
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10: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
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
}, (type, args) => {
|
|
|
|
applyButton.loading = false
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
|
2019-12-05 00:59:14 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "InvalidUserInContext")
|
|
|
|
txt = qsTr("Can't start chatting with yourself")
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "InvalidUserId")
|
|
|
|
txt = qsTr("Invalid user ID, expected format is " +
|
|
|
|
"@username:homeserver")
|
2020-06-03 10:24:03 +10:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
if (type === "MatrixNotFound")
|
|
|
|
txt = qsTr("User not found, please verify the entered ID")
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-06-25 22:32:08 +10: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()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
enabled: account && account.presence !== "offline"
|
|
|
|
|
2020-07-12 12:52:14 +10:00
|
|
|
footer: AutoDirectionLayout {
|
2020-06-25 22:32:08 +10:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
CancelButton {
|
|
|
|
onClicked: {
|
|
|
|
userField.item.text = ""
|
|
|
|
errorMessage.text = ""
|
|
|
|
pageLoader.showPrevious()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2020-08-21 19:08:12 +10:00
|
|
|
onKeyboardAccept: if (applyButton.enabled) applyButton.clicked()
|
2020-06-26 00:27:24 +10:00
|
|
|
onKeyboardCancel: cancel()
|
2019-11-10 05:20:53 +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 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
|
2020-06-03 10:14:55 +10:00
|
|
|
|
|
|
|
HTextField {
|
|
|
|
width: parent.width
|
|
|
|
placeholderText: qsTr("@example:matrix.org")
|
|
|
|
error: Boolean(errorMessage.text)
|
|
|
|
}
|
2019-11-10 05:20:53 +11:00
|
|
|
}
|
|
|
|
|
2019-11-10 05:57:46 +11:00
|
|
|
EncryptCheckBox {
|
|
|
|
id: encryptCheckBox
|
|
|
|
|
2019-12-08 00:38:36 +11:00
|
|
|
Layout.fillWidth: true
|
2019-11-10 05:57:46 +11:00
|
|
|
}
|
|
|
|
|
2019-11-10 05:20:53 +11:00
|
|
|
HLabel {
|
|
|
|
id: errorMessage
|
2020-07-17 15:45:02 +10:00
|
|
|
wrapMode: HLabel.Wrap
|
2019-11-10 05:20:53 +11:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: theme.colors.errorText
|
|
|
|
|
|
|
|
visible: Layout.maximumHeight > 0
|
|
|
|
Layout.maximumHeight: text ? implicitHeight : 0
|
|
|
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
}
|