fix(@desktop/chat): Create separate chatInput for each conversation

Moved the statusChatInput to the repeater in stackview so that each conversation has its own separate textInput area which maintains its own state

fixes #1351
This commit is contained in:
Khushboo Mehta 2021-09-21 14:26:32 +02:00 committed by Iuri Matias
parent 2b408fe6cd
commit bd9ae45ae0
2 changed files with 131 additions and 118 deletions

View File

@ -35,7 +35,6 @@ Item {
property bool contactRequestReceived: profileModel.contacts.contactRequestReceived(activeChatId) property bool contactRequestReceived: profileModel.contacts.contactRequestReceived(activeChatId)
property string currentNotificationChatId property string currentNotificationChatId
property string currentNotificationCommunityId property string currentNotificationCommunityId
property alias input: chatInput
property string hoveredMessage property string hoveredMessage
property string activeMessage property string activeMessage
property var currentTime: 0 property var currentTime: 0
@ -43,7 +42,13 @@ Item {
property Timer timer: Timer { } property Timer timer: Timer { }
property var userList property var userList
property var onActivated: function () { property var onActivated: function () {
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
}
function hideChatInputExtendedArea () {
if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.hideExtendedArea()
} }
function setHovered(messageId, hovered) { function setHovered(messageId, hovered) {
@ -74,7 +79,8 @@ Item {
let sticker = chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "sticker") let sticker = chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "sticker")
let contentType = chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "contentType") let contentType = chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "contentType")
chatInput.showReplyArea(userName, message, identicon, contentType, image, sticker) if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.showReplyArea(userName, message, identicon, contentType, image, sticker)
} }
function requestAddressForTransaction(address, amount, tokenAddress, tokenDecimals = 18) { function requestAddressForTransaction(address, amount, tokenAddress, tokenDecimals = 18) {
@ -295,7 +301,14 @@ Item {
currentIndex: chatsModel.messageView.getMessageListIndex(chatsModel.channelView.activeChannelIndex) currentIndex: chatsModel.messageView.getMessageListIndex(chatsModel.channelView.activeChannelIndex)
Repeater { Repeater {
model: chatsModel.messageView model: chatsModel.messageView
ColumnLayout {
property alias chatInput: chatInput
Loader { Loader {
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredWidth: parent.width
active: stackLayoutChatMessages.currentIndex === index active: stackLayoutChatMessages.currentIndex === index
sourceComponent: ChatMessages { sourceComponent: ChatMessages {
id: chatMessages id: chatMessages
@ -306,24 +319,6 @@ Item {
} }
} }
} }
}
}
Connections {
target: chatsModel.channelView
onActiveChannelChanged: {
isBlocked = profileModel.contacts.isContactBlocked(activeChatId);
chatInput.suggestions.hide();
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
}
}
ChatRequestMessage {
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
Layout.fillWidth: true
Layout.bottomMargin: Style.current.bigPadding
}
Item { Item {
id: inputArea id: inputArea
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
@ -417,7 +412,24 @@ Item {
} }
} }
} }
}
Connections {
target: chatsModel.channelView
onActiveChannelChanged: {
isBlocked = profileModel.contacts.isContactBlocked(activeChatId);
chatInput.suggestions.hide();
if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
}
}
}
}
}
ChatRequestMessage {
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
Layout.fillWidth: true
Layout.bottomMargin: Style.current.bigPadding
} }
} }
@ -613,7 +625,8 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
} }
Connections { Connections {

View File

@ -205,7 +205,7 @@ Item {
badge.border.width: 2 badge.border.width: 2
onClicked: { onClicked: {
if (chatsModel.communities.activeCommunity.active) { if (chatsModel.communities.activeCommunity.active) {
chatLayoutContainer.chatColumn.input.hideExtendedArea(); chatLayoutContainer.chatColumn.hideChatInputExtendedArea();
chatsModel.communities.activeCommunity.active = false chatsModel.communities.activeCommunity.active = false
} }
appMain.changeAppSection(Constants.chat) appMain.changeAppSection(Constants.chat)