From ef1d62d45cf55f90bbca26488489e1b14f9add64 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 22 Oct 2023 13:39:34 +0000 Subject: [PATCH] ActionsHandler poperties Make sure that all low level components get ActionsHandler through actual properties rather than magically --- src/qml/ChatBar.qml | 10 +++++++++- src/qml/ChatBox.qml | 9 +++++++++ src/qml/MessageEditComponent.qml | 10 +++++++++- src/qml/RoomPage.qml | 14 +++++++++----- src/qml/TextDelegate.qml | 1 + src/qml/TimelineView.qml | 10 ++++++++++ 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/qml/ChatBar.qml b/src/qml/ChatBar.qml index ee9235786..4c49936df 100644 --- a/src/qml/ChatBar.qml +++ b/src/qml/ChatBar.qml @@ -50,6 +50,14 @@ QQC2.Control { property NeoChatConnection connection + /** + * @brief The ActionsHandler object to use. + * + * This is expected to have the correct room set otherwise messages will be sent + * to the wrong room. + */ + required property ActionsHandler actionsHandler + /** * @brief The list of actions in the ChatBar. * @@ -478,7 +486,7 @@ QQC2.Control { } function postMessage() { - actionsHandler.handleMessageEvent(_private.chatBarCache); + root.actionsHandler.handleMessageEvent(_private.chatBarCache); repeatTimer.stop() root.currentRoom.markAllMessagesAsRead(); textField.clear(); diff --git a/src/qml/ChatBox.qml b/src/qml/ChatBox.qml index 2ebada030..064010c9d 100644 --- a/src/qml/ChatBox.qml +++ b/src/qml/ChatBox.qml @@ -38,6 +38,14 @@ ColumnLayout { required property NeoChatConnection connection + /** + * @brief The ActionsHandler object to use. + * + * This is expected to have the correct room set otherwise messages will be sent + * to the wrong room. + */ + required property ActionsHandler actionsHandler + /** * @brief A message has been sent from the chat bar. */ @@ -75,6 +83,7 @@ ColumnLayout { Layout.preferredHeight: Math.round(implicitHeight) currentRoom: root.currentRoom + actionsHandler: root.actionsHandler FontMetrics { id: chatBarFontMetrics diff --git a/src/qml/MessageEditComponent.qml b/src/qml/MessageEditComponent.qml index 7f4b2860c..2b4cfa6cf 100644 --- a/src/qml/MessageEditComponent.qml +++ b/src/qml/MessageEditComponent.qml @@ -18,6 +18,14 @@ QQC2.TextArea { _private.chatBarCache.relationIdChanged.connect(_private.updateEditText) } + /** + * @brief The ActionsHandler object to use. + * + * This is expected to have the correct room set otherwise messages will be sent + * to the wrong room. + */ + required property ActionsHandler actionsHandler + property string messageId property var minimumHeight: editButtons.height + topPadding + bottomPadding @@ -137,7 +145,7 @@ QQC2.TextArea { } function postEdit() { - actionsHandler.handleMessageEvent(_private.chatBarCache); + root.actionsHandler.handleMessageEvent(_private.chatBarCache); root.clear(); _private.chatBarCache.editId = ""; } diff --git a/src/qml/RoomPage.qml b/src/qml/RoomPage.qml index 4564ecfa9..bdcfea435 100644 --- a/src/qml/RoomPage.qml +++ b/src/qml/RoomPage.qml @@ -60,6 +60,13 @@ Kirigami.Page { */ property MediaMessageFilterModel mediaMessageFilterModel: RoomManager.mediaMessageFilterModel + /** + * @brief The ActionsHandler object to use. + */ + property ActionsHandler actionsHandler: ActionsHandler { + room: root.currentRoom + } + property bool loading: !root.currentRoom || (root.currentRoom.timelineSize === 0 && !root.currentRoom.allHistoryLoaded) /// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation. @@ -114,6 +121,7 @@ Kirigami.Page { currentRoom: root.currentRoom messageEventModel: root.messageEventModel messageFilterModel: root.messageFilterModel + actionsHandler: root.actionsHandler onFocusChatBox: { if (chatBoxLoader.item) { chatBoxLoader.item.forceActiveFocus() @@ -155,6 +163,7 @@ Kirigami.Page { width: parent.width currentRoom: root.currentRoom connection: root.connection + actionsHandler: root.actionsHandler onMessageSent: { if (!timelineViewLoader.item.atYEnd) { timelineViewLoader.item.goToLastMessage(); @@ -180,11 +189,6 @@ Kirigami.Page { } } - ActionsHandler { - id: actionsHandler - room: root.currentRoom - } - Shortcut { sequence: StandardKey.Cancel onActivated: { diff --git a/src/qml/TextDelegate.qml b/src/qml/TextDelegate.qml index cb0d17d96..53ca8b4f2 100644 --- a/src/qml/TextDelegate.qml +++ b/src/qml/TextDelegate.qml @@ -63,6 +63,7 @@ MessageDelegate { active: visible sourceComponent: MessageEditComponent { room: currentRoom + actionsHandler: root.ListView.view.actionsHandler messageId: root.eventId } } diff --git a/src/qml/TimelineView.qml b/src/qml/TimelineView.qml index c7734edb9..44682933e 100644 --- a/src/qml/TimelineView.qml +++ b/src/qml/TimelineView.qml @@ -41,6 +41,14 @@ QQC2.ScrollView { */ required property MessageFilterModel messageFilterModel + /** + * @brief The ActionsHandler object to use. + * + * This is expected to have the correct room set otherwise messages will be sent + * to the wrong room. + */ + required property ActionsHandler actionsHandler + readonly property bool atYEnd: messageListView.atYEnd /// Used to determine if scrolling to the bottom should mark the message as unread @@ -52,6 +60,8 @@ QQC2.ScrollView { id: messageListView // So that delegates can access the current room properly. readonly property NeoChatRoom currentRoom: root.currentRoom + // So that delegates can access the actionsHandler properly. + readonly property ActionsHandler actionsHandler: root.actionsHandler readonly property int largestVisibleIndex: count > 0 ? indexAt(contentX + (width / 2), contentY + height - 1) : -1 readonly property var sectionBannerItem: contentHeight >= height ? itemAtIndex(sectionBannerIndex()) : undefined