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.
This commit is contained in:
James Graham
2024-01-15 19:47:50 +00:00
parent f1efc1f17d
commit 85cda8ffa7
13 changed files with 41 additions and 45 deletions

View File

@@ -53,7 +53,7 @@ MessageDelegate {
PropertyChanges { PropertyChanges {
target: playButton target: playButton
icon.name: "media-playback-start" icon.name: "media-playback-start"
onClicked: currentRoom.downloadFile(root.eventId) onClicked: root.room.downloadFile(root.eventId)
} }
}, },
State { State {
@@ -67,7 +67,7 @@ MessageDelegate {
target: playButton target: playButton
icon.name: "media-playback-stop" icon.name: "media-playback-stop"
onClicked: { onClicked: {
currentRoom.cancelFileTransfer(root.eventId) root.room.cancelFileTransfer(root.eventId)
} }
} }
}, },

View File

@@ -11,9 +11,12 @@ import org.kde.neochat
DelegateChooser { DelegateChooser {
id: root id: root
/**
* @brief The NeoChatRoom the delegate is being displayed in.
*/
required property NeoChatRoom room
role: "delegateType" role: "delegateType"
property var room
required property NeoChatConnection connection
DelegateChoice { DelegateChoice {
roleValue: DelegateType.State roleValue: DelegateType.State
@@ -23,63 +26,63 @@ DelegateChooser {
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Emote roleValue: DelegateType.Emote
delegate: TextDelegate { delegate: TextDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Message roleValue: DelegateType.Message
delegate: TextDelegate { delegate: TextDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Notice roleValue: DelegateType.Notice
delegate: TextDelegate { delegate: TextDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Image roleValue: DelegateType.Image
delegate: ImageDelegate { delegate: ImageDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Sticker roleValue: DelegateType.Sticker
delegate: ImageDelegate { delegate: ImageDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Audio roleValue: DelegateType.Audio
delegate: AudioDelegate { delegate: AudioDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Video roleValue: DelegateType.Video
delegate: VideoDelegate { delegate: VideoDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.File roleValue: DelegateType.File
delegate: FileDelegate { delegate: FileDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Encrypted roleValue: DelegateType.Encrypted
delegate: EncryptedDelegate { delegate: EncryptedDelegate {
connection: root.connection room: root.room
} }
} }
@@ -91,14 +94,14 @@ DelegateChooser {
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Poll roleValue: DelegateType.Poll
delegate: PollDelegate { delegate: PollDelegate {
connection: root.connection room: root.room
} }
} }
DelegateChoice { DelegateChoice {
roleValue: DelegateType.Location roleValue: DelegateType.Location
delegate: LocationDelegate { delegate: LocationDelegate {
connection: root.connection room: root.room
} }
} }
@@ -106,7 +109,6 @@ DelegateChooser {
roleValue: DelegateType.LiveLocation roleValue: DelegateType.LiveLocation
delegate: LiveLocationDelegate { delegate: LiveLocationDelegate {
room: root.room room: root.room
connection: root.connection
} }
} }

View File

@@ -54,7 +54,7 @@ MessageDelegate {
function saveFileAs() { function saveFileAs() {
const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay) const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
dialog.open() dialog.open()
dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(root.eventId) dialog.currentFile = dialog.folder + "/" + root.room.fileNameToDownload(root.eventId)
} }
function openSavedFile() { function openSavedFile() {
@@ -117,7 +117,7 @@ MessageDelegate {
target: downloadButton target: downloadButton
icon.name: "media-playback-stop" icon.name: "media-playback-stop"
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; stops downloading the message's file", "Stop Download") 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 { State {
@@ -159,7 +159,7 @@ MessageDelegate {
icon.name: "document-open" icon.name: "document-open"
onClicked: { onClicked: {
autoOpenFile = true; 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") 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) { if (autoOpenFile) {
UrlHelper.copyTo(root.progressInfo.localPath, file) UrlHelper.copyTo(root.progressInfo.localPath, file)
} else { } else {
currentRoom.download(root.eventId, file); root.room.download(root.eventId, file);
} }
} }
} }
@@ -198,7 +198,7 @@ MessageDelegate {
id: itinerary id: itinerary
model: ItineraryModel { model: ItineraryModel {
id: itineraryModel id: itineraryModel
connection: root.connection connection: root.room.connection
} }
delegate: DelegateChooser { delegate: DelegateChooser {
role: "type" role: "type"

View File

@@ -148,7 +148,7 @@ MessageDelegate {
openSavedFile() openSavedFile()
} else { } else {
openOnFinished = true 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))
} }
} }

View File

@@ -18,12 +18,11 @@ import org.kde.neochat
MessageDelegate { MessageDelegate {
id: root id: root
property alias room: liveLocationModel.room
bubbleContent: ColumnLayout { bubbleContent: ColumnLayout {
LiveLocationsModel { LiveLocationsModel {
id: liveLocationModel id: liveLocationModel
eventId: root.eventId eventId: root.eventId
room: root.room
} }
MapView { MapView {
id: mapView id: mapView

View File

@@ -29,6 +29,11 @@ import org.kde.neochat.config
TimelineDelegate { TimelineDelegate {
id: root id: root
/**
* @brief The NeoChatRoom the delegate is being displayed in.
*/
required property NeoChatRoom room
/** /**
* @brief The index of the delegate in the model. * @brief The index of the delegate in the model.
*/ */
@@ -244,8 +249,6 @@ TimelineDelegate {
*/ */
readonly property alias hovered: bubble.hovered readonly property alias hovered: bubble.hovered
required property NeoChatConnection connection
/** /**
* @brief Open the context menu for the message. * @brief Open the context menu for the message.
*/ */
@@ -326,7 +329,7 @@ TimelineDelegate {
Component.onCompleted: { Component.onCompleted: {
if (root.isReply && root.replyDelegateType === DelegateType.Other) { 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 visible: root.showReactions
model: root.reaction model: root.reaction
onReactionClicked: (reaction) => currentRoom.toggleReaction(root.eventId, reaction) onReactionClicked: (reaction) => root.room.toggleReaction(root.eventId, reaction)
} }
AvatarFlow { AvatarFlow {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight

View File

@@ -36,7 +36,7 @@ MessageDelegate {
delegate: RowLayout { delegate: RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
CheckBox { 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"]) onClicked: root.pollHandler.sendPollAnswer(root.eventId, modelData["id"])
enabled: !root.pollHandler.hasEnded enabled: !root.pollHandler.hasEnded
} }

View File

@@ -38,9 +38,6 @@ QQC2.ScrollView {
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
ListView { ListView {
// So that delegates can access current room properly.
readonly property NeoChatRoom currentRoom: root.currentRoom
clip: true clip: true
verticalLayoutDirection: ListView.BottomToTop verticalLayoutDirection: ListView.BottomToTop
@@ -55,7 +52,7 @@ QQC2.ScrollView {
alwaysShowAuthor: true alwaysShowAuthor: true
alwaysMaxWidth: true alwaysMaxWidth: true
cardBackground: false cardBackground: false
connection: root.connection room: root.currentRoom
} }
} }
@@ -65,7 +62,7 @@ QQC2.ScrollView {
alwaysShowAuthor: true alwaysShowAuthor: true
alwaysMaxWidth: true alwaysMaxWidth: true
cardBackground: false cardBackground: false
connection: root.connection room: root.currentRoom
} }
} }
} }

View File

@@ -128,7 +128,6 @@ Kirigami.Page {
chatBarLoader.item.forceActiveFocus() chatBarLoader.item.forceActiveFocus()
} }
} }
connection: root.connection
} }
} }

View File

@@ -87,7 +87,7 @@ Kirigami.ScrollablePage {
model: searchModel model: searchModel
delegate: EventDelegate { delegate: EventDelegate {
connection: root.connection room: root.currentRoom
} }
} }
} }

View File

@@ -43,7 +43,7 @@ MessageDelegate {
RichLabel { RichLabel {
id: label id: label
Layout.fillWidth: true Layout.fillWidth: true
visible: currentRoom.editCache.editId !== root.eventId visible: root.room.editCache.editId !== root.eventId
isReply: root.isReply isReply: root.isReply
@@ -59,17 +59,17 @@ MessageDelegate {
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: item ? item.minimumHeight : -1 Layout.minimumHeight: item ? item.minimumHeight : -1
Layout.preferredWidth: item ? item.preferredWidth : -1 Layout.preferredWidth: item ? item.preferredWidth : -1
visible: currentRoom.editCache.editId === root.eventId visible: root.room.editCache.editId === root.eventId
active: visible active: visible
sourceComponent: MessageEditComponent { sourceComponent: MessageEditComponent {
room: currentRoom room: root.room
actionsHandler: root.ListView.view.actionsHandler actionsHandler: root.ListView.view.actionsHandler
messageId: root.eventId messageId: root.eventId
} }
} }
LinkPreviewDelegate { LinkPreviewDelegate {
Layout.fillWidth: true 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 linkPreviewer: root.linkPreview
indicatorEnabled: root.isVisibleInTimeline() indicatorEnabled: root.isVisibleInTimeline()
} }

View File

@@ -17,7 +17,6 @@ import org.kde.neochat.config
QQC2.ScrollView { QQC2.ScrollView {
id: root id: root
required property NeoChatRoom currentRoom required property NeoChatRoom currentRoom
required property NeoChatConnection connection
onCurrentRoomChanged: { onCurrentRoomChanged: {
roomChanging = true; roomChanging = true;
roomChangingTimer.restart() roomChangingTimer.restart()
@@ -63,8 +62,6 @@ QQC2.ScrollView {
ListView { ListView {
id: messageListView 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. // So that delegates can access the actionsHandler properly.
readonly property ActionsHandler actionsHandler: root.actionsHandler readonly property ActionsHandler actionsHandler: root.actionsHandler
@@ -153,7 +150,6 @@ QQC2.ScrollView {
delegate: EventDelegate { delegate: EventDelegate {
room: root.currentRoom room: root.currentRoom
connection: root.connection
} }
KirigamiComponents.FloatingButton { KirigamiComponents.FloatingButton {

View File

@@ -358,7 +358,7 @@ MessageDelegate {
playSavedFile() playSavedFile()
} else { } else {
playOnFinished = true 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))
} }
} }