Declare currentRoom property

Make sure `currentRoom` is a property for every qml component where it's used in `chatbar`.
This commit is contained in:
James Graham
2023-08-05 16:50:06 +00:00
committed by Carl Schwan
parent 9eeff06328
commit 4b3dac025f
7 changed files with 55 additions and 34 deletions

View File

@@ -36,7 +36,7 @@ QQC2.Control {
/** /**
* @brief The current room that user is viewing. * @brief The current room that user is viewing.
*/ */
property NeoChatRoom currentRoom required property NeoChatRoom currentRoom
/** /**
* @brief The QQC2.TextArea object. * @brief The QQC2.TextArea object.
@@ -55,10 +55,10 @@ QQC2.Control {
Kirigami.Action { Kirigami.Action {
id: attachmentAction id: attachmentAction
property bool isBusy: currentRoom && currentRoom.hasFileUploading property bool isBusy: root.currentRoom && root.currentRoom.hasFileUploading
// Matrix does not allow sending attachments in replies // Matrix does not allow sending attachments in replies
visible: currentRoom.chatBoxReplyId.length === 0 && currentRoom.chatBoxAttachmentPath.length === 0 visible: root.currentRoom.chatBoxReplyId.length === 0 && root.currentRoom.chatBoxAttachmentPath.length === 0
icon.name: "mail-attachment" icon.name: "mail-attachment"
text: i18n("Attach an image or file") text: i18n("Attach an image or file")
displayHint: Kirigami.DisplayHint.IconOnly displayHint: Kirigami.DisplayHint.IconOnly
@@ -72,7 +72,7 @@ QQC2.Control {
if (!path) { if (!path) {
return; return;
} }
currentRoom.chatBoxAttachmentPath = path; root.currentRoom.chatBoxAttachmentPath = path;
}) })
fileDialog.open() fileDialog.open()
} }
@@ -106,7 +106,7 @@ QQC2.Control {
displayHint: QQC2.AbstractButton.IconOnly displayHint: QQC2.AbstractButton.IconOnly
onTriggered: { onTriggered: {
locationChooserComponent.createObject(QQC2.ApplicationWindow.overlay, {room: currentRoom}).open() locationChooserComponent.createObject(QQC2.ApplicationWindow.overlay, {room: root.currentRoom}).open()
} }
}, },
Kirigami.Action { Kirigami.Action {
@@ -162,10 +162,10 @@ QQC2.Control {
leftPadding: LayoutMirroring.enabled ? actionsRow.width : Kirigami.Units.largeSpacing leftPadding: LayoutMirroring.enabled ? actionsRow.width : Kirigami.Units.largeSpacing
rightPadding: LayoutMirroring.enabled ? Kirigami.Units.largeSpacing : actionsRow.width + x * 2 + Kirigami.Units.largeSpacing * 2 rightPadding: LayoutMirroring.enabled ? Kirigami.Units.largeSpacing : actionsRow.width + x * 2 + Kirigami.Units.largeSpacing * 2
placeholderText: readOnly ? i18n("This room is encrypted. Build libQuotient with encryption enabled to send encrypted messages.") : currentRoom.usesEncryption ? i18n("Send an encrypted message…") : currentRoom.chatBoxAttachmentPath.length > 0 ? i18n("Set an attachment caption...") : i18n("Send a message…") placeholderText: readOnly ? i18n("This room is encrypted. Build libQuotient with encryption enabled to send encrypted messages.") : root.currentRoom.usesEncryption ? i18n("Send an encrypted message…") : root.currentRoom.chatBoxAttachmentPath.length > 0 ? i18n("Set an attachment caption...") : i18n("Send a message…")
verticalAlignment: TextEdit.AlignVCenter verticalAlignment: TextEdit.AlignVCenter
wrapMode: Text.Wrap wrapMode: Text.Wrap
readOnly: (currentRoom.usesEncryption && !Controller.encryptionSupported) readOnly: (root.currentRoom.usesEncryption && !Controller.encryptionSupported)
Accessible.description: placeholderText Accessible.description: placeholderText
@@ -177,10 +177,10 @@ QQC2.Control {
onTextChanged: { onTextChanged: {
if (!repeatTimer.running && Config.typingNotifications) { if (!repeatTimer.running && Config.typingNotifications) {
var textExists = text.length > 0 var textExists = text.length > 0
currentRoom.sendTypingNotification(textExists) root.currentRoom.sendTypingNotification(textExists)
textExists ? repeatTimer.start() : repeatTimer.stop() textExists ? repeatTimer.start() : repeatTimer.stop()
} }
currentRoom.chatBoxText = text root.currentRoom.chatBoxText = text
} }
onCursorRectangleChanged: chatBarScrollView.ensureVisible(cursorRectangle) onCursorRectangleChanged: chatBarScrollView.ensureVisible(cursorRectangle)
onSelectedTextChanged: { onSelectedTextChanged: {
@@ -207,7 +207,7 @@ QQC2.Control {
remove(cursorPosition, cursorPosition + 1) remove(cursorPosition, cursorPosition + 1)
} }
if (textField.text == selectedText || textField.text.length <= 1) { if (textField.text == selectedText || textField.text.length <= 1) {
currentRoom.sendTypingNotification(false) root.currentRoom.sendTypingNotification(false)
repeatTimer.stop() repeatTimer.stop()
} }
if (quickFormatBar.visible) { if (quickFormatBar.visible) {
@@ -241,16 +241,16 @@ QQC2.Control {
if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier) { if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier) {
root.pasteImage(); root.pasteImage();
} else if (event.key === Qt.Key_Up && event.modifiers & Qt.ControlModifier) { } else if (event.key === Qt.Key_Up && event.modifiers & Qt.ControlModifier) {
currentRoom.replyLastMessage(); root.currentRoom.replyLastMessage();
} else if (event.key === Qt.Key_Up && textField.text.length === 0) { } else if (event.key === Qt.Key_Up && textField.text.length === 0) {
currentRoom.editLastMessage(); root.currentRoom.editLastMessage();
} else if (event.key === Qt.Key_Up && completionMenu.visible) { } else if (event.key === Qt.Key_Up && completionMenu.visible) {
completionMenu.decrementIndex() completionMenu.decrementIndex()
} else if (event.key === Qt.Key_Down && completionMenu.visible) { } else if (event.key === Qt.Key_Down && completionMenu.visible) {
completionMenu.incrementIndex() completionMenu.incrementIndex()
} else if (event.key === Qt.Key_Backspace) { } else if (event.key === Qt.Key_Backspace) {
if (textField.text == selectedText || textField.text.length <= 1) { if (textField.text == selectedText || textField.text.length <= 1) {
currentRoom.sendTypingNotification(false) root.currentRoom.sendTypingNotification(false)
repeatTimer.stop() repeatTimer.stop()
} }
if (quickFormatBar.visible && selectedText.length > 0) { if (quickFormatBar.visible && selectedText.length > 0) {
@@ -282,19 +282,19 @@ QQC2.Control {
Component { Component {
id: replyPane id: replyPane
ReplyPane { ReplyPane {
userName: currentRoom.chatBoxReplyUser.displayName userName: root.currentRoom.chatBoxReplyUser.displayName
userColor: currentRoom.chatBoxReplyUser.color userColor: root.currentRoom.chatBoxReplyUser.color
userAvatar: currentRoom.chatBoxReplyUser.avatarSource userAvatar: root.currentRoom.chatBoxReplyUser.avatarSource
text: currentRoom.chatBoxReplyMessage text: root.currentRoom.chatBoxReplyMessage
} }
} }
Component { Component {
id: attachmentPane id: attachmentPane
AttachmentPane { AttachmentPane {
attachmentPath: currentRoom.chatBoxAttachmentPath attachmentPath: root.currentRoom.chatBoxAttachmentPath
onAttachmentCancelled: { onAttachmentCancelled: {
currentRoom.chatBoxAttachmentPath = ""; root.currentRoom.chatBoxAttachmentPath = "";
root.forceActiveFocus() root.forceActiveFocus()
} }
} }
@@ -346,8 +346,8 @@ QQC2.Control {
text: i18nc("@action:button", "Cancel reply") text: i18nc("@action:button", "Cancel reply")
icon.name: "dialog-close" icon.name: "dialog-close"
onTriggered: { onTriggered: {
currentRoom.chatBoxReplyId = ""; root.currentRoom.chatBoxReplyId = "";
currentRoom.chatBoxAttachmentPath = ""; root.currentRoom.chatBoxAttachmentPath = "";
root.forceActiveFocus() root.forceActiveFocus()
} }
} }
@@ -388,7 +388,7 @@ QQC2.Control {
PieProgressBar { PieProgressBar {
visible: modelData.isBusy visible: modelData.isBusy
progress: currentRoom.fileUploadingProgress progress: root.currentRoom.fileUploadingProgress
} }
} }
} }
@@ -403,6 +403,8 @@ QQC2.Control {
includeCustom: true includeCustom: true
closeOnChosen: false closeOnChosen: false
currentRoom: root.currentRoom
onChosen: insertText(emoji) onChosen: insertText(emoji)
onClosed: if (emojiButton.checked) emojiButton.checked = false onClosed: if (emojiButton.checked) emojiButton.checked = false
} }
@@ -468,15 +470,15 @@ QQC2.Control {
if (localPath.length === 0) { if (localPath.length === 0) {
return; return;
} }
currentRoom.chatBoxAttachmentPath = localPath root.currentRoom.chatBoxAttachmentPath = localPath
} }
function postMessage() { function postMessage() {
actionsHandler.handleNewMessage(); actionsHandler.handleNewMessage();
repeatTimer.stop() repeatTimer.stop()
currentRoom.markAllMessagesAsRead(); root.currentRoom.markAllMessagesAsRead();
textField.clear(); textField.clear();
currentRoom.chatBoxReplyId = ""; root.currentRoom.chatBoxReplyId = "";
messageSent() messageSent()
} }

View File

@@ -35,7 +35,7 @@ ColumnLayout {
/** /**
* @brief The current room that user is viewing. * @brief The current room that user is viewing.
*/ */
property NeoChatRoom currentRoom required property NeoChatRoom currentRoom
/** /**
* @brief A message has been sent from the chat bar. * @brief A message has been sent from the chat bar.

View File

@@ -10,6 +10,11 @@ import org.kde.neochat 1.0
ColumnLayout { ColumnLayout {
id: root id: root
/**
* @brief The current room that user is viewing.
*/
property NeoChatRoom currentRoom
property bool includeCustom: false property bool includeCustom: false
property bool showQuickReaction: false property bool showQuickReaction: false
@@ -151,7 +156,7 @@ ColumnLayout {
ImagePacksModel { ImagePacksModel {
id: stickerPackModel id: stickerPackModel
room: currentRoom room: root.currentRoom
showStickers: true showStickers: true
showEmoticons: false showEmoticons: false
} }
@@ -160,7 +165,7 @@ ColumnLayout {
id: stickerModel id: stickerModel
model: stickerPackModel model: stickerPackModel
packIndex: 0 packIndex: 0
room: currentRoom room: root.currentRoom
} }
EmoticonFilterModel { EmoticonFilterModel {

View File

@@ -6,6 +6,7 @@ import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import org.kde.kirigami 2.15 as Kirigami import org.kde.kirigami 2.15 as Kirigami
import org.kde.neochat 1.0
/** /**
* @brief A component that provides a set of actions when a message is hovered in the timeline. * @brief A component that provides a set of actions when a message is hovered in the timeline.
@@ -16,6 +17,11 @@ import org.kde.kirigami 2.15 as Kirigami
QQC2.Control { QQC2.Control {
id: root id: root
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom currentRoom
/** /**
* @brief Whether the actions should be shown. * @brief Whether the actions should be shown.
*/ */
@@ -108,6 +114,7 @@ QQC2.Control {
EmojiDialog { EmojiDialog {
id: emojiDialog id: emojiDialog
currentRoom: root.currentRoom
showQuickReaction: true showQuickReaction: true
onChosen: (emoji) => root.reactClicked(emoji) onChosen: (emoji) => root.reactClicked(emoji)
} }

View File

@@ -310,6 +310,7 @@ QQC2.ScrollView {
y: delegate ? delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing : 0 y: delegate ? delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing : 0
width: delegate ? delegate.bubbleWidth : Kirigami.Units.gridUnit * 4 width: delegate ? delegate.bubbleWidth : Kirigami.Units.gridUnit * 4
currentRoom: root.currentRoom
showActions: delegate && delegate.hovered showActions: delegate && delegate.hovered
verified: delegate && delegate.verified verified: delegate && delegate.verified
editable: delegate && delegate.author.isLocalUser && (delegate.delegateType === MessageEventModel.Emote || delegate.delegateType === MessageEventModel.Message) editable: delegate && delegate.author.isLocalUser && (delegate.delegateType === MessageEventModel.Emote || delegate.delegateType === MessageEventModel.Message)

View File

@@ -11,6 +11,11 @@ import org.kde.neochat 1.0
QQC2.Popup { QQC2.Popup {
id: emojiPopup id: emojiPopup
/**
* @brief The current room that user is viewing.
*/
property NeoChatRoom currentRoom
property bool includeCustom: false property bool includeCustom: false
property bool closeOnChosen: true property bool closeOnChosen: true
property bool showQuickReaction: false property bool showQuickReaction: false
@@ -52,6 +57,7 @@ QQC2.Popup {
contentItem: EmojiPicker { contentItem: EmojiPicker {
id: emojiPicker id: emojiPicker
height: 400 height: 400
currentRoom: root.currentRoom
includeCustom: emojiPopup.includeCustom includeCustom: emojiPopup.includeCustom
showQuickReaction: emojiPopup.showQuickReaction showQuickReaction: emojiPopup.showQuickReaction
onChosen: { onChosen: {

View File

@@ -25,7 +25,7 @@ Kirigami.Page {
/// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation. /// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation.
property bool disableCancelShortcut: false property bool disableCancelShortcut: false
title: currentRoom.displayName title: root.currentRoom.displayName
focus: true focus: true
padding: 0 padding: 0
@@ -66,7 +66,7 @@ Kirigami.Page {
Loader { Loader {
id: timelineViewLoader id: timelineViewLoader
anchors.fill: parent anchors.fill: parent
active: currentRoom && !currentRoom.isInvite && !root.loading active: root.currentRoom && !root.currentRoom.isInvite && !root.loading
sourceComponent: TimelineView { sourceComponent: TimelineView {
id: timelineView id: timelineView
currentRoom: root.currentRoom currentRoom: root.currentRoom
@@ -80,7 +80,7 @@ Kirigami.Page {
Loader { Loader {
id: invitationLoader id: invitationLoader
active: currentRoom && currentRoom.isInvite active: root.currentRoom && root.currentRoom.isInvite
anchors.centerIn: parent anchors.centerIn: parent
sourceComponent: InvitationView { sourceComponent: InvitationView {
currentRoom: root.currentRoom currentRoom: root.currentRoom
@@ -106,7 +106,7 @@ Kirigami.Page {
sourceComponent: ChatBox { sourceComponent: ChatBox {
id: chatBox id: chatBox
width: parent.width width: parent.width
currentRoom: currentRoom currentRoom: root.currentRoom
onMessageSent: { onMessageSent: {
if (!timelineViewLoader.item.atYEnd) { if (!timelineViewLoader.item.atYEnd) {
timelineViewLoader.item.goToLastMessage(); timelineViewLoader.item.goToLastMessage();
@@ -140,9 +140,9 @@ Kirigami.Page {
Shortcut { Shortcut {
sequence: StandardKey.Cancel sequence: StandardKey.Cancel
onActivated: { onActivated: {
if (!timelineViewLoader.item.atYEnd || currentRoom.hasUnreadMessages) { if (!timelineViewLoader.item.atYEnd || root.currentRoom.hasUnreadMessages) {
goToLastMessage(); goToLastMessage();
currentRoom.markAllMessagesAsRead(); root.currentRoom.markAllMessagesAsRead();
} else { } else {
applicationWindow().pageStack.get(0).forceActiveFocus(); applicationWindow().pageStack.get(0).forceActiveFocus();
} }