From 85cda8ffa75a82d7f422cf05f3a72c07287a6656 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 15 Jan 2024 19:47:50 +0000 Subject: [PATCH] Current Room Messages Make sure that message delegates are getting the room object directly rather than requiring the assumption that currentRoom is declared somewhere higher up. --- src/qml/AudioDelegate.qml | 4 ++-- src/qml/EventDelegate.qml | 30 ++++++++++++++++-------------- src/qml/FileDelegate.qml | 10 +++++----- src/qml/ImageDelegate.qml | 2 +- src/qml/LiveLocationDelegate.qml | 3 +-- src/qml/MessageDelegate.qml | 11 +++++++---- src/qml/PollDelegate.qml | 2 +- src/qml/RoomMedia.qml | 7 ++----- src/qml/RoomPage.qml | 1 - src/qml/SearchPage.qml | 2 +- src/qml/TextDelegate.qml | 8 ++++---- src/qml/TimelineView.qml | 4 ---- src/qml/VideoDelegate.qml | 2 +- 13 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/qml/AudioDelegate.qml b/src/qml/AudioDelegate.qml index 90625c42f..2bad3c874 100644 --- a/src/qml/AudioDelegate.qml +++ b/src/qml/AudioDelegate.qml @@ -53,7 +53,7 @@ MessageDelegate { PropertyChanges { target: playButton icon.name: "media-playback-start" - onClicked: currentRoom.downloadFile(root.eventId) + onClicked: root.room.downloadFile(root.eventId) } }, State { @@ -67,7 +67,7 @@ MessageDelegate { target: playButton icon.name: "media-playback-stop" onClicked: { - currentRoom.cancelFileTransfer(root.eventId) + root.room.cancelFileTransfer(root.eventId) } } }, diff --git a/src/qml/EventDelegate.qml b/src/qml/EventDelegate.qml index 783714e55..e29be02f4 100644 --- a/src/qml/EventDelegate.qml +++ b/src/qml/EventDelegate.qml @@ -11,9 +11,12 @@ import org.kde.neochat DelegateChooser { id: root + /** + * @brief The NeoChatRoom the delegate is being displayed in. + */ + required property NeoChatRoom room + role: "delegateType" - property var room - required property NeoChatConnection connection DelegateChoice { roleValue: DelegateType.State @@ -23,63 +26,63 @@ DelegateChooser { DelegateChoice { roleValue: DelegateType.Emote delegate: TextDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Message delegate: TextDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Notice delegate: TextDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Image delegate: ImageDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Sticker delegate: ImageDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Audio delegate: AudioDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Video delegate: VideoDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.File delegate: FileDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Encrypted delegate: EncryptedDelegate { - connection: root.connection + room: root.room } } @@ -91,14 +94,14 @@ DelegateChooser { DelegateChoice { roleValue: DelegateType.Poll delegate: PollDelegate { - connection: root.connection + room: root.room } } DelegateChoice { roleValue: DelegateType.Location delegate: LocationDelegate { - connection: root.connection + room: root.room } } @@ -106,7 +109,6 @@ DelegateChooser { roleValue: DelegateType.LiveLocation delegate: LiveLocationDelegate { room: root.room - connection: root.connection } } diff --git a/src/qml/FileDelegate.qml b/src/qml/FileDelegate.qml index b4e074e21..cdb25a881 100644 --- a/src/qml/FileDelegate.qml +++ b/src/qml/FileDelegate.qml @@ -54,7 +54,7 @@ MessageDelegate { function saveFileAs() { const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay) dialog.open() - dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(root.eventId) + dialog.currentFile = dialog.folder + "/" + root.room.fileNameToDownload(root.eventId) } function openSavedFile() { @@ -117,7 +117,7 @@ MessageDelegate { target: downloadButton icon.name: "media-playback-stop" QQC2.ToolTip.text: i18nc("tooltip for a button on a message; stops downloading the message's file", "Stop Download") - onClicked: currentRoom.cancelFileTransfer(root.eventId) + onClicked: root.room.cancelFileTransfer(root.eventId) } }, State { @@ -159,7 +159,7 @@ MessageDelegate { icon.name: "document-open" onClicked: { autoOpenFile = true; - currentRoom.downloadTempFile(root.eventId); + root.room.downloadTempFile(root.eventId); } QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File") @@ -188,7 +188,7 @@ MessageDelegate { if (autoOpenFile) { UrlHelper.copyTo(root.progressInfo.localPath, file) } else { - currentRoom.download(root.eventId, file); + root.room.download(root.eventId, file); } } } @@ -198,7 +198,7 @@ MessageDelegate { id: itinerary model: ItineraryModel { id: itineraryModel - connection: root.connection + connection: root.room.connection } delegate: DelegateChooser { role: "type" diff --git a/src/qml/ImageDelegate.qml b/src/qml/ImageDelegate.qml index decf8819d..bcef15f58 100644 --- a/src/qml/ImageDelegate.qml +++ b/src/qml/ImageDelegate.qml @@ -148,7 +148,7 @@ MessageDelegate { openSavedFile() } else { openOnFinished = true - ListView.view.currentRoom.downloadFile(root.eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + ListView.view.currentRoom.fileNameToDownload(root.eventId)) + root.room.downloadFile(root.eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + root.room.fileNameToDownload(root.eventId)) } } diff --git a/src/qml/LiveLocationDelegate.qml b/src/qml/LiveLocationDelegate.qml index 909aada0c..8d29154f8 100644 --- a/src/qml/LiveLocationDelegate.qml +++ b/src/qml/LiveLocationDelegate.qml @@ -18,12 +18,11 @@ import org.kde.neochat MessageDelegate { id: root - property alias room: liveLocationModel.room - bubbleContent: ColumnLayout { LiveLocationsModel { id: liveLocationModel eventId: root.eventId + room: root.room } MapView { id: mapView diff --git a/src/qml/MessageDelegate.qml b/src/qml/MessageDelegate.qml index d548c7b76..b3e370314 100644 --- a/src/qml/MessageDelegate.qml +++ b/src/qml/MessageDelegate.qml @@ -29,6 +29,11 @@ import org.kde.neochat.config TimelineDelegate { id: root + /** + * @brief The NeoChatRoom the delegate is being displayed in. + */ + required property NeoChatRoom room + /** * @brief The index of the delegate in the model. */ @@ -244,8 +249,6 @@ TimelineDelegate { */ readonly property alias hovered: bubble.hovered - required property NeoChatConnection connection - /** * @brief Open the context menu for the message. */ @@ -326,7 +329,7 @@ TimelineDelegate { Component.onCompleted: { if (root.isReply && root.replyDelegateType === DelegateType.Other) { - currentRoom.loadReply(root.eventId, root.replyId) + root.room.loadReply(root.eventId, root.replyId) } } @@ -437,7 +440,7 @@ TimelineDelegate { visible: root.showReactions model: root.reaction - onReactionClicked: (reaction) => currentRoom.toggleReaction(root.eventId, reaction) + onReactionClicked: (reaction) => root.room.toggleReaction(root.eventId, reaction) } AvatarFlow { Layout.alignment: Qt.AlignRight diff --git a/src/qml/PollDelegate.qml b/src/qml/PollDelegate.qml index 9b92c944b..a5178b700 100644 --- a/src/qml/PollDelegate.qml +++ b/src/qml/PollDelegate.qml @@ -36,7 +36,7 @@ MessageDelegate { delegate: RowLayout { Layout.fillWidth: true CheckBox { - checked: root.pollHandler.answers[currentRoom.localUser.id] ? root.pollHandler.answers[currentRoom.localUser.id].includes(modelData["id"]) : false + checked: root.pollHandler.answers[root.room.localUser.id] ? root.pollHandler.answers[root.room.localUser.id].includes(modelData["id"]) : false onClicked: root.pollHandler.sendPollAnswer(root.eventId, modelData["id"]) enabled: !root.pollHandler.hasEnded } diff --git a/src/qml/RoomMedia.qml b/src/qml/RoomMedia.qml index 151f426f5..36cad157d 100644 --- a/src/qml/RoomMedia.qml +++ b/src/qml/RoomMedia.qml @@ -38,9 +38,6 @@ QQC2.ScrollView { QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff ListView { - // So that delegates can access current room properly. - readonly property NeoChatRoom currentRoom: root.currentRoom - clip: true verticalLayoutDirection: ListView.BottomToTop @@ -55,7 +52,7 @@ QQC2.ScrollView { alwaysShowAuthor: true alwaysMaxWidth: true cardBackground: false - connection: root.connection + room: root.currentRoom } } @@ -65,7 +62,7 @@ QQC2.ScrollView { alwaysShowAuthor: true alwaysMaxWidth: true cardBackground: false - connection: root.connection + room: root.currentRoom } } } diff --git a/src/qml/RoomPage.qml b/src/qml/RoomPage.qml index 60de6e3c9..737e16625 100644 --- a/src/qml/RoomPage.qml +++ b/src/qml/RoomPage.qml @@ -128,7 +128,6 @@ Kirigami.Page { chatBarLoader.item.forceActiveFocus() } } - connection: root.connection } } diff --git a/src/qml/SearchPage.qml b/src/qml/SearchPage.qml index 3b3ef28f3..9787448ee 100644 --- a/src/qml/SearchPage.qml +++ b/src/qml/SearchPage.qml @@ -87,7 +87,7 @@ Kirigami.ScrollablePage { model: searchModel delegate: EventDelegate { - connection: root.connection + room: root.currentRoom } } } diff --git a/src/qml/TextDelegate.qml b/src/qml/TextDelegate.qml index 53ca8b4f2..29553b512 100644 --- a/src/qml/TextDelegate.qml +++ b/src/qml/TextDelegate.qml @@ -43,7 +43,7 @@ MessageDelegate { RichLabel { id: label Layout.fillWidth: true - visible: currentRoom.editCache.editId !== root.eventId + visible: root.room.editCache.editId !== root.eventId isReply: root.isReply @@ -59,17 +59,17 @@ MessageDelegate { Layout.fillWidth: true Layout.minimumHeight: item ? item.minimumHeight : -1 Layout.preferredWidth: item ? item.preferredWidth : -1 - visible: currentRoom.editCache.editId === root.eventId + visible: root.room.editCache.editId === root.eventId active: visible sourceComponent: MessageEditComponent { - room: currentRoom + room: root.room actionsHandler: root.ListView.view.actionsHandler messageId: root.eventId } } LinkPreviewDelegate { Layout.fillWidth: true - active: !currentRoom.usesEncryption && currentRoom.urlPreviewEnabled && Config.showLinkPreview && root.showLinkPreview && !root.linkPreview.empty + active: !root.room.usesEncryption && root.room.urlPreviewEnabled && Config.showLinkPreview && root.showLinkPreview && !root.linkPreview.empty linkPreviewer: root.linkPreview indicatorEnabled: root.isVisibleInTimeline() } diff --git a/src/qml/TimelineView.qml b/src/qml/TimelineView.qml index 84db50151..3b9087d61 100644 --- a/src/qml/TimelineView.qml +++ b/src/qml/TimelineView.qml @@ -17,7 +17,6 @@ import org.kde.neochat.config QQC2.ScrollView { id: root required property NeoChatRoom currentRoom - required property NeoChatConnection connection onCurrentRoomChanged: { roomChanging = true; roomChangingTimer.restart() @@ -63,8 +62,6 @@ QQC2.ScrollView { ListView { 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 @@ -153,7 +150,6 @@ QQC2.ScrollView { delegate: EventDelegate { room: root.currentRoom - connection: root.connection } KirigamiComponents.FloatingButton { diff --git a/src/qml/VideoDelegate.qml b/src/qml/VideoDelegate.qml index c3c301f5b..60893794f 100644 --- a/src/qml/VideoDelegate.qml +++ b/src/qml/VideoDelegate.qml @@ -358,7 +358,7 @@ MessageDelegate { playSavedFile() } else { playOnFinished = true - ListView.view.currentRoom.downloadFile(root.eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + ListView.view.currentRoom.fileNameToDownload(root.eventId)) + root.room.downloadFile(root.eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + root.room.fileNameToDownload(root.eventId)) } }