From d5032430f91533c7a91c49adde3c1b6b75542de5 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 10 Jun 2021 15:20:43 -0400 Subject: [PATCH] feat(act-center): scroll to the clicked message in the act center Fixes #2681 --- ui/app/AppLayouts/Chat/ChatColumn.qml | 4 ++++ .../AppLayouts/Chat/ChatColumn/ActivityCenter.qml | 13 +++++++++++++ ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml | 12 ++++++++++++ ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 2 +- .../ChatColumn/MessageComponents/ChatButtons.qml | 4 +++- .../ChatColumn/MessageComponents/CompactMessage.qml | 12 ++++++++---- .../MessageComponents/MessageMouseArea.qml | 11 +++++++---- 7 files changed, 48 insertions(+), 10 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatColumn.qml b/ui/app/AppLayouts/Chat/ChatColumn.qml index a49899acf7..3c28467131 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn.qml @@ -191,6 +191,10 @@ StackLayout { Timer { id: timer } + + function positionAtMessage(messageId) { + stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].item.scrollToMessage(messageId) + } ColumnLayout { spacing: 0 diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml b/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml index 0e0ac85153..23206090bd 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml @@ -183,6 +183,18 @@ Popup { pinnedBy: model.message.pinnedBy pinnedMessage: model.message.isPinned activityCenterMessage: true + clickMessage: function (isProfileClick) { + if (isProfileClick) { + const pk = model.message.fromAuthor + const userProfileImage = appMain.getProfileImage(pk) + return openProfilePopup(chatsModel.userNameOrAlias(pk), pk, userProfileImage || utilsModel.generateIdenticon(pk)) + } + + activityCenter.close() + chatsModel.setActiveChannel(model.message.chatId) + positionAtMessage(model.message.messageId) + } + prevMessageIndex: { if (notificationDelegate.idx === 0) { return 0 @@ -222,6 +234,7 @@ Popup { } ActivityChannelBadge { + id: badge name: model.name chatId: model.chatId notificationType: model.notificationType diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 5bf09eb6d9..2720749777 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -17,6 +17,7 @@ ScrollView { id: root property alias chatLogView: chatLogView + property alias scrollToMessage: chatLogView.scrollToMessage property var messageList: MessagesData {} property bool loadingMessages: false @@ -64,6 +65,17 @@ ScrollView { } } + property var scrollToMessage: function (messageId) { + let item + for (let i = 0; i < messageListDelegate.count; i++) { + item = messageListDelegate.items.get(i) + if (item.model.messageId === messageId) { + chatLogView.positionViewAtIndex(i, ListView.Center) + return + } + } + } + Connections { id: contentHeightConnection enabled: true diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index 77433e37c1..6d1a023bd7 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -176,7 +176,7 @@ Item { } } - function clickMessage(isProfileClick, isSticker = false, isImage = false, image = null, emojiOnly = false, hideEmojiPicker = false) { + property var clickMessage: function(isProfileClick, isSticker = false, isImage = false, image = null, emojiOnly = false, hideEmojiPicker = false) { if (placeholderMessage || activityCenterMessage) { return } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatButtons.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatButtons.qml index 433f4bbde6..cb9625769d 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatButtons.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatButtons.qml @@ -11,7 +11,9 @@ Rectangle { property int contentType: 2 id: buttonsContainer - visible: (buttonsContainer.parentIsHovered || isMessageActive) && contentType !== Constants.transactionType + visible: !activityCenterMessage && + (buttonsContainer.parentIsHovered || isMessageActive) + && contentType !== Constants.transactionType width: buttonRow.width + buttonsContainer.containerMargin * 2 height: 36 radius: Style.current.radius diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml index 0e7520fcac..37160fe686 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml @@ -23,10 +23,12 @@ Item { + (dateGroupLbl.visible ? dateGroupLbl.height + dateGroupLbl.anchors.topMargin : 0) MouseArea { - enabled: !placeholderMessage && !activityCenterMessage + enabled: !placeholderMessage anchors.fill: messageContainer - acceptedButtons: Qt.RightButton - onClicked: messageMouseArea.clicked(mouse) + acceptedButtons: activityCenterMessage ? Qt.LeftButton : Qt.RightButton + onClicked: { + messageMouseArea.clicked(mouse) + } } ChatButtons { @@ -238,6 +240,7 @@ Item { MessageMouseArea { id: messageMouseArea anchors.fill: stickerLoader.active ? stickerLoader : chatText + z: activityCenterMessage ? chatText.z + 1 : chatText.z -1 } Loader { @@ -320,7 +323,8 @@ Item { } HoverHandler { - enabled: forceHoverHandler || (typeof messageContextMenu !== "undefined" && typeof profilePopupOpened !== "undefined" && !messageContextMenu.opened && !profilePopupOpened && !popupOpened) + enabled: !activityCenterMessage && + (forceHoverHandler || (typeof messageContextMenu !== "undefined" && typeof profilePopupOpened !== "undefined" && !messageContextMenu.opened && !profilePopupOpened && !popupOpened)) onHoveredChanged: setHovered(messageId, hovered) } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/MessageMouseArea.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/MessageMouseArea.qml index ac29d1b6bf..a59d729ac3 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/MessageMouseArea.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/MessageMouseArea.qml @@ -3,13 +3,16 @@ import "../../../../../shared" import "../../../../../imports" MouseArea { - enabled: !placeholderMessage && !activityCenterMessage + enabled: !placeholderMessage cursorShape: chatText.hoveredLink ? Qt.PointingHandCursor : undefined - acceptedButtons: Qt.RightButton | Qt.LeftButton + acceptedButtons: Qt.LeftButton | Qt.RightButton z: 50 onClicked: { - if(mouse.button & Qt.RightButton) { - clickMessage(false, isSticker, false); + if (activityCenterMessage) { + return clickMessage(false, isSticker, false) + } + if(mouse.button === Qt.RightButton) { + clickMessage(false, isSticker, false) if (typeof isMessageActive !== "undefined") { setMessageActive(messageId, true) }