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

103 lines
2.6 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 "../../Base"
HBox {
id: addChatBox
clickButtonOnEnter: "apply"
onFocusChanged: userField.item.forceActiveFocus()
2019-11-10 05:20:53 +11:00
buttonModel: [
{
name: "apply",
text: qsTr("Start chat"),
iconName: "start-direct-chat",
enabled: Boolean(userField.item.text.trim())
},
2019-11-10 05:20:53 +11:00
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
buttonCallbacks: ({
apply: button => {
button.loading = true
errorMessage.text = ""
const args = [userField.item.text.trim(), encryptCheckBox.checked]
2019-11-10 05:20:53 +11:00
py.callClientCoro(userId, "new_direct_chat", args, roomId => {
button.loading = false
errorMessage.text = ""
pageLoader.showRoom(userId, roomId)
}, (type, args) => {
button.loading = false
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
if (type === "InvalidUserInContext")
2019-12-12 03:42:59 +11:00
txt = qsTr("Can't start chatting with yourself")
2019-11-10 05:20:53 +11:00
2019-12-05 00:59:14 +11:00
if (type === "InvalidUserId")
txt = qsTr("Invalid user ID, expected format is " +
"@username:homeserver")
2019-11-10 05:20:53 +11:00
if (type === "UserNotFound")
txt = qsTr("This user does not exist")
2019-11-10 05:20:53 +11:00
errorMessage.text = txt
})
},
cancel: button => {
userField.item.text = ""
errorMessage.text = ""
2019-11-10 05:20:53 +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
}
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
}
}