2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-05-27 21:09:12 +00:00
|
|
|
import "../../../shared"
|
2020-05-25 20:34:26 +00:00
|
|
|
import "../../../imports"
|
2020-06-25 16:27:46 +00:00
|
|
|
import "./components"
|
2020-05-27 21:59:34 +00:00
|
|
|
import "./ChatColumn"
|
2020-07-20 19:29:57 +00:00
|
|
|
import "./data"
|
2020-05-25 20:34:26 +00:00
|
|
|
|
2020-05-26 18:16:07 +00:00
|
|
|
StackLayout {
|
2020-07-10 15:37:23 +00:00
|
|
|
id: chatColumnLayout
|
2020-05-26 18:16:07 +00:00
|
|
|
property int chatGroupsListViewCount: 0
|
2020-07-20 17:04:33 +00:00
|
|
|
|
2020-07-09 17:47:36 +00:00
|
|
|
property bool isReply: false
|
2020-07-20 17:04:33 +00:00
|
|
|
property bool isImage: false
|
|
|
|
|
|
|
|
property bool isExtendedInput: isReply || isImage
|
|
|
|
|
2020-07-15 16:19:25 +00:00
|
|
|
property bool isConnected: false
|
2020-08-10 13:06:46 +00:00
|
|
|
property string contactToRemove: ""
|
|
|
|
|
2020-09-23 07:28:20 +00:00
|
|
|
property var onActivated: function () {
|
|
|
|
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-26 18:16:07 +00:00
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
2020-05-28 12:56:43 +00:00
|
|
|
Layout.minimumWidth: 300
|
2020-05-25 20:34:26 +00:00
|
|
|
|
2020-06-05 14:50:39 +00:00
|
|
|
currentIndex: chatsModel.activeChannelIndex > -1 && chatGroupsListViewCount > 0 ? 0 : 1
|
2020-05-26 15:55:32 +00:00
|
|
|
|
2020-09-23 16:13:39 +00:00
|
|
|
function showReplyArea() {
|
2020-07-20 17:04:33 +00:00
|
|
|
isReply = true;
|
|
|
|
isImage = false;
|
|
|
|
replyAreaContainer.setup()
|
|
|
|
}
|
|
|
|
|
2020-09-23 16:13:39 +00:00
|
|
|
function showImageArea(imagePath) {
|
2020-07-20 17:04:33 +00:00
|
|
|
isImage = true;
|
|
|
|
isReply = false;
|
|
|
|
sendImageArea.image = imagePath[0];
|
|
|
|
}
|
|
|
|
|
2020-09-23 16:13:39 +00:00
|
|
|
function hideExtendedArea() {
|
2020-07-20 17:04:33 +00:00
|
|
|
isImage = false;
|
|
|
|
isReply = false;
|
|
|
|
replyAreaContainer.setup();
|
|
|
|
sendImageArea.image = "";
|
|
|
|
}
|
|
|
|
|
2020-05-26 18:16:07 +00:00
|
|
|
ColumnLayout {
|
2020-07-09 17:47:36 +00:00
|
|
|
spacing: 0
|
2020-05-26 15:55:32 +00:00
|
|
|
|
2020-05-26 18:16:07 +00:00
|
|
|
RowLayout {
|
|
|
|
id: chatTopBar
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
2020-05-26 15:55:32 +00:00
|
|
|
Layout.fillWidth: true
|
2020-05-26 18:16:07 +00:00
|
|
|
z: 60
|
2020-07-09 17:47:36 +00:00
|
|
|
spacing: 0
|
2020-07-15 16:19:25 +00:00
|
|
|
TopBar {
|
|
|
|
id: topBar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.fillWidth: true
|
|
|
|
z: 60
|
|
|
|
Rectangle {
|
2020-07-24 14:33:17 +00:00
|
|
|
Component.onCompleted: {
|
2020-07-24 14:33:17 +00:00
|
|
|
isConnected = chatsModel.isOnline
|
2020-07-24 14:33:17 +00:00
|
|
|
if(!isConnected){
|
|
|
|
connectedStatusRect.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 16:19:25 +00:00
|
|
|
id: connectedStatusRect
|
|
|
|
Layout.fillWidth: true
|
|
|
|
height: 40;
|
|
|
|
color: isConnected ? Style.current.green : Style.current.darkGrey
|
|
|
|
visible: false
|
|
|
|
Text {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
color: Style.current.white
|
|
|
|
id: connectedStatusLbl
|
|
|
|
text: isConnected ?
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Connected"
|
|
|
|
qsTrId("connected") :
|
|
|
|
//% "Disconnected"
|
|
|
|
qsTrId("disconnected")
|
2020-07-15 16:19:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: chatsModel
|
|
|
|
onOnlineStatusChanged: {
|
2020-07-24 14:33:17 +00:00
|
|
|
if (connected == isConnected) return;
|
|
|
|
isConnected = connected;
|
|
|
|
if(isConnected){
|
2020-07-15 16:19:25 +00:00
|
|
|
timer.setTimeout(function(){
|
|
|
|
connectedStatusRect.visible = false;
|
|
|
|
}, 5000);
|
|
|
|
} else {
|
|
|
|
connectedStatusRect.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-25 20:34:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 18:16:07 +00:00
|
|
|
RowLayout {
|
|
|
|
id: chatContainer
|
2020-05-25 20:34:26 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2020-05-26 18:16:07 +00:00
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
2020-07-09 17:47:36 +00:00
|
|
|
spacing: 0
|
2020-05-28 17:34:54 +00:00
|
|
|
ChatMessages {
|
2020-07-09 17:47:36 +00:00
|
|
|
id: chatMessages
|
2020-05-28 17:34:54 +00:00
|
|
|
messageList: chatsModel.messageList
|
|
|
|
}
|
2020-05-27 22:59:17 +00:00
|
|
|
}
|
2020-05-25 20:34:26 +00:00
|
|
|
|
2020-09-12 18:22:07 +00:00
|
|
|
ImagePopup {
|
|
|
|
id: imagePopup
|
|
|
|
}
|
|
|
|
|
2020-07-20 19:29:57 +00:00
|
|
|
EmojiReactions {
|
|
|
|
id: reactionModel
|
|
|
|
}
|
|
|
|
|
2020-08-03 17:17:03 +00:00
|
|
|
MessageContextMenu {
|
2020-07-09 17:47:36 +00:00
|
|
|
id: messageContextMenu
|
|
|
|
}
|
|
|
|
|
2020-07-14 11:40:58 +00:00
|
|
|
ListModel {
|
|
|
|
id: suggestions
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: chatsModel
|
|
|
|
onActiveChannelChanged: {
|
2020-09-23 07:28:20 +00:00
|
|
|
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
|
2020-07-14 11:40:58 +00:00
|
|
|
suggestions.clear()
|
|
|
|
for (let i = 0; i < chatsModel.suggestionList.rowCount(); i++) {
|
|
|
|
suggestions.append({
|
|
|
|
alias: chatsModel.suggestionList.rowData(i, "alias"),
|
|
|
|
ensName: chatsModel.suggestionList.rowData(i, "ensName"),
|
|
|
|
address: chatsModel.suggestionList.rowData(i, "address"),
|
|
|
|
identicon: chatsModel.suggestionList.rowData(i, "identicon"),
|
|
|
|
ensVerified: chatsModel.suggestionList.rowData(i, "ensVerified")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 03:23:49 +00:00
|
|
|
Rectangle {
|
2020-07-09 17:47:36 +00:00
|
|
|
id: inputArea
|
2020-07-13 18:45:54 +00:00
|
|
|
color: Style.current.background
|
2020-07-09 17:47:36 +00:00
|
|
|
border.width: 1
|
2020-07-13 18:45:54 +00:00
|
|
|
border.color: Style.current.border
|
2020-06-24 03:23:49 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
2020-05-25 20:34:26 +00:00
|
|
|
Layout.fillWidth: true
|
2020-06-24 03:23:49 +00:00
|
|
|
Layout.preferredWidth: parent.width
|
2020-09-28 13:24:03 +00:00
|
|
|
height: (!isExtendedInput ? 70 : 140) * chatInput.extraHeightFactor
|
2020-06-24 03:23:49 +00:00
|
|
|
Layout.preferredHeight: height
|
2020-07-09 17:47:36 +00:00
|
|
|
|
2020-07-20 15:38:24 +00:00
|
|
|
SuggestionBox {
|
|
|
|
id: suggestionsBox
|
|
|
|
model: suggestions
|
|
|
|
width: chatContainer.width
|
|
|
|
anchors.bottom: inputArea.top
|
|
|
|
anchors.left: inputArea.left
|
|
|
|
filter: chatInput.textInput.text
|
2020-07-20 16:48:23 +00:00
|
|
|
cursorPosition: chatInput.textInput.cursorPosition
|
2020-07-20 15:38:24 +00:00
|
|
|
property: "ensName, alias"
|
2020-07-20 16:48:23 +00:00
|
|
|
onItemSelected: function (item, lastAtPosition, lastCursorPosition) {
|
2020-08-27 17:43:06 +00:00
|
|
|
let hasEmoji = Emoji.hasEmoji(chatInput.textInput.text)
|
|
|
|
let currentText = hasEmoji ?
|
|
|
|
chatsModel.plainText(Emoji.deparse(chatInput.textInput.text)) :
|
|
|
|
chatsModel.plainText(chatInput.textInput.text);
|
|
|
|
|
2020-07-20 15:38:24 +00:00
|
|
|
let aliasName = item[suggestionsBox.property.split(",").map(p => p.trim()).find(p => !!item[p])]
|
2020-08-27 17:47:32 +00:00
|
|
|
aliasName = aliasName.replace(".stateofus.eth", "")
|
2020-07-20 15:38:24 +00:00
|
|
|
let nameLen = aliasName.length + 2 // We're doing a +2 here because of the `@` and the trailing whitespace
|
|
|
|
let position = 0;
|
|
|
|
let text = ""
|
|
|
|
|
2020-07-20 16:48:23 +00:00
|
|
|
if (currentText === "@") {
|
2020-07-20 15:38:24 +00:00
|
|
|
position = nameLen
|
|
|
|
text = "@" + aliasName + " "
|
|
|
|
} else {
|
2020-08-27 17:43:06 +00:00
|
|
|
let left = currentText.substring(0, lastAtPosition)
|
|
|
|
let right = currentText.substring(hasEmoji ? lastCursorPosition + 2 : lastCursorPosition)
|
2020-07-31 21:30:55 +00:00
|
|
|
text = `${left} @${aliasName} ${right}`
|
2020-07-20 15:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 17:43:06 +00:00
|
|
|
chatInput.textInput.text = hasEmoji ? Emoji.parse(text, "26x26") : text
|
|
|
|
chatInput.textInput.cursorPosition = lastAtPosition + aliasName.length + 2
|
2020-07-20 15:38:24 +00:00
|
|
|
suggestionsBox.suggestionsModel.clear()
|
|
|
|
}
|
|
|
|
}
|
2020-07-09 17:47:36 +00:00
|
|
|
|
|
|
|
ReplyArea {
|
2020-07-10 22:22:39 +00:00
|
|
|
id: replyAreaContainer
|
2020-07-09 17:47:36 +00:00
|
|
|
visible: isReply
|
|
|
|
}
|
2020-05-25 20:34:26 +00:00
|
|
|
|
2020-07-20 17:04:33 +00:00
|
|
|
SendImageArea {
|
|
|
|
id: sendImageArea
|
|
|
|
visible: isImage
|
|
|
|
}
|
|
|
|
|
2020-09-07 11:47:00 +00:00
|
|
|
Loader {
|
|
|
|
active: chatsModel.loadingMessages
|
|
|
|
sourceComponent: loadingIndicator
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: chatInput.top
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.bottomMargin: Style.current.padding
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: loadingIndicator
|
|
|
|
SVGImage {
|
|
|
|
id: loadingImg
|
|
|
|
source: "../../../app/img/loading.svg"
|
|
|
|
width: 25
|
|
|
|
height: 25
|
|
|
|
fillMode: Image.Stretch
|
|
|
|
RotationAnimator {
|
|
|
|
target: loadingImg;
|
|
|
|
from: 0;
|
|
|
|
to: 360;
|
|
|
|
duration: 1200
|
|
|
|
running: true
|
|
|
|
loops: Animation.Infinite
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 03:23:49 +00:00
|
|
|
ChatInput {
|
2020-07-14 11:40:58 +00:00
|
|
|
id: chatInput
|
2020-07-09 17:47:36 +00:00
|
|
|
height: 40
|
2020-07-20 17:04:33 +00:00
|
|
|
anchors.top: {
|
|
|
|
if(!isExtendedInput){
|
|
|
|
return inputArea.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isReply){
|
|
|
|
return replyAreaContainer.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isImage){
|
|
|
|
return sendImageArea.bottom;
|
|
|
|
}
|
|
|
|
}
|
2020-07-09 17:47:36 +00:00
|
|
|
anchors.topMargin: 4
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
}
|
2020-05-25 20:34:26 +00:00
|
|
|
}
|
2020-05-26 18:16:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 00:12:07 +00:00
|
|
|
EmptyChat {}
|
2020-05-25 20:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
2020-05-27 17:26:21 +00:00
|
|
|
D{i:0;formeditorColor:"#ffffff";height:770;width:800}
|
2020-05-25 20:34:26 +00:00
|
|
|
}
|
|
|
|
##^##*/
|