From bf666c20f50acb6258f31cfa860f6936660c7435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Mon, 7 Oct 2024 14:31:53 +0200 Subject: [PATCH] fix(chat): chat input accepts DnD for blocked users - do not allow DND when the StatusChatInput is disabled - remove `Global.dragArea` variable from the Global singleton - move the `DropAreaPanel` into `StatusChatInput` and handle its enabling from there Fixes #16451 --- storybook/pages/StatusChatInputPage.qml | 1 - .../qmlTests/tests/tst_StatusChatInput.qml | 4 --- ui/app/mainui/AppMain.qml | 25 ------------------- ui/app/mainui/panels/DropAreaPanel.qml | 9 +++---- ui/app/mainui/qmldir | 1 + .../shared/status/StatusChatImageLoader.qml | 3 +++ ui/imports/shared/status/StatusChatInput.qml | 12 +++++---- ui/imports/utils/Global.qml | 1 - 8 files changed, 14 insertions(+), 42 deletions(-) diff --git a/storybook/pages/StatusChatInputPage.qml b/storybook/pages/StatusChatInputPage.qml index e030f269a6..51d04c2342 100644 --- a/storybook/pages/StatusChatInputPage.qml +++ b/storybook/pages/StatusChatInputPage.qml @@ -32,7 +32,6 @@ SplitView { } Component.onCompleted: { Utils.globalUtilsInst = globalUtilsMock.globalUtils - Global.dragArea = null globalUtilsMock.ready = true } } diff --git a/storybook/qmlTests/tests/tst_StatusChatInput.qml b/storybook/qmlTests/tests/tst_StatusChatInput.qml index 2d01f39d5b..707dc96314 100644 --- a/storybook/qmlTests/tests/tst_StatusChatInput.qml +++ b/storybook/qmlTests/tests/tst_StatusChatInput.qml @@ -702,9 +702,5 @@ Item { function isCompressedPubKey(publicKey) { return false } - - Component.onCompleted: { - Global.dragArea = root - } } } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index f05ac687ff..9f967fc65e 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -50,8 +50,6 @@ import mainui.activitycenter.popups 1.0 import SortFilterProxyModel 0.2 -import "panels" - Item { id: appMain @@ -1353,14 +1351,6 @@ Item { ChatLayout { id: chatLayoutContainer - Binding { - target: rootDropAreaPanel - property: "enabled" - value: chatLayoutContainer.currentIndex === 0 // Meaning: Chats / channels view - when: visible - restoreMode: Binding.RestoreBindingOrValue - } - sharedRootStore: appMain.sharedRootStore rootStore: ChatStores.RootStore { contactsStore: appMain.rootStore.contactStore @@ -1487,14 +1477,6 @@ Item { readonly property bool isManageCommunityEnabledInAdvanced: appMain.rootStore.profileSectionStore.advancedStore.isManageCommunityOnTestModeEnabled - Binding { - target: rootDropAreaPanel - property: "enabled" - value: chatLayoutComponent.currentIndex === 0 // Meaning: Chats / channels view - when: visible - restoreMode: Binding.RestoreBindingOrValue - } - Connections { target: Global function onSwitchToCommunitySettings(communityId: string) { @@ -2153,13 +2135,6 @@ Item { } } - DropAreaPanel { - id: rootDropAreaPanel - - width: appMain.width - height: appMain.height - } - Loader { id: userAgreementLoader active: production && !localAppSettings.testEnvironment diff --git a/ui/app/mainui/panels/DropAreaPanel.qml b/ui/app/mainui/panels/DropAreaPanel.qml index 6d0b58aad9..dc01530c9a 100644 --- a/ui/app/mainui/panels/DropAreaPanel.qml +++ b/ui/app/mainui/panels/DropAreaPanel.qml @@ -1,4 +1,5 @@ -import QtQuick 2.14 +import QtQuick 2.15 + import utils 1.0 DropArea { @@ -13,10 +14,6 @@ DropArea { rptDraggedPreviews.model = [] } - Component.onCompleted: { - Global.dragArea = this; - } - onDropped: (drop) => { if (enabled) { droppedOnValidScreen(drop) @@ -42,7 +39,7 @@ DropArea { onExited: cleanup() Loader { - active: root.containsDrag + active: root.containsDrag && root.enabled width: active ? parent.width : 0 height: active ? parent.height : 0 sourceComponent: Rectangle { diff --git a/ui/app/mainui/qmldir b/ui/app/mainui/qmldir index a604f097de..a4b6e9c0e1 100644 --- a/ui/app/mainui/qmldir +++ b/ui/app/mainui/qmldir @@ -2,3 +2,4 @@ AppMain 1.0 AppMain.qml SplashScreen 1.0 SplashScreen.qml Popups 1.0 Popups.qml StatusTrayIcon 1.0 StatusTrayIcon.qml +DropAreaPanel 1.0 panels/DropAreaPanel.qml diff --git a/ui/imports/shared/status/StatusChatImageLoader.qml b/ui/imports/shared/status/StatusChatImageLoader.qml index e9563acbbc..0f09ed4daa 100644 --- a/ui/imports/shared/status/StatusChatImageLoader.qml +++ b/ui/imports/shared/status/StatusChatImageLoader.qml @@ -1,8 +1,11 @@ import QtQuick 2.15 import QtQuick.Window 2.15 import QtGraphicalEffects 1.15 + import shared.panels 1.0 +import utils 1.0 + Item { id: root diff --git a/ui/imports/shared/status/StatusChatInput.qml b/ui/imports/shared/status/StatusChatInput.qml index 019572f0be..cc447d9701 100644 --- a/ui/imports/shared/status/StatusChatInput.qml +++ b/ui/imports/shared/status/StatusChatInput.qml @@ -11,6 +11,8 @@ import shared.panels 1.0 import shared.popups 1.0 import shared.stores 1.0 as SharedStores +import mainui 1.0 + //TODO remove this dependency import AppLayouts.Chat.panels 1.0 import AppLayouts.Chat.stores 1.0 as ChatStores @@ -948,11 +950,11 @@ Rectangle { messageInputField.forceActiveFocus(); } - Connections { - target: Global.dragArea - enabled: control.visible - ignoreUnknownSignals: true - function onDroppedOnValidScreen(drop) { + DropAreaPanel { + enabled: control.visible && control.enabled + parent: Overlay.overlay + anchors.fill: parent + onDroppedOnValidScreen: (drop) => { let dropUrls = drop.urls if (!drop.hasUrls) { console.warn("Trying to drop, list of URLs is empty tho; formats:", drop.formats) diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index d879447346..d468ba51ef 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -5,7 +5,6 @@ import QtQml 2.15 QtObject { id: root - property var dragArea property bool activityPopupOpened: false property int settingsSubsection: Constants.settingsSubsection.profile property int settingsSubSubsection: -1