Fix the reply an edit text being shown in all chat rooms when multiple windows are open

Fix the reply an edit text being shown in all chat rooms when multiple windows are open. This is done by changing chatBoxHelper from a singleton to being instantiated for each instance of roompage.

BUG: 454963
This commit is contained in:
James Graham
2022-08-26 19:33:20 +00:00
parent fdb424e65e
commit 6748a2d21d
8 changed files with 39 additions and 35 deletions

View File

@@ -14,14 +14,14 @@ import NeoChat.Page 1.0
Loader { Loader {
id: root id: root
property var attachmentMimetype: FileType.mimeTypeForUrl(ChatBoxHelper.attachmentPath) property var attachmentMimetype: FileType.mimeTypeForUrl(chatBoxHelper.attachmentPath)
readonly property bool hasImage: attachmentMimetype.valid && FileType.supportedImageFormats.includes(attachmentMimetype.preferredSuffix) readonly property bool hasImage: attachmentMimetype.valid && FileType.supportedImageFormats.includes(attachmentMimetype.preferredSuffix)
active: visible active: visible
sourceComponent: Component { sourceComponent: Component {
Pane { Pane {
id: attachmentPane id: attachmentPane
property string baseFileName: ChatBoxHelper.attachmentPath.toString().substring(ChatBoxHelper.attachmentPath.toString().lastIndexOf('/') + 1, ChatBoxHelper.attachmentPath.length) property string baseFileName: chatBoxHelper.attachmentPath.toString().substring(chatBoxHelper.attachmentPath.toString().lastIndexOf('/') + 1, chatBoxHelper.attachmentPath.length)
Kirigami.Theme.colorSet: Kirigami.Theme.View Kirigami.Theme.colorSet: Kirigami.Theme.View
contentItem: Item { contentItem: Item {
@@ -46,7 +46,7 @@ Loader {
asynchronous: true asynchronous: true
cache: false // Cache is not needed. Images will rarely be shown repeatedly. cache: false // Cache is not needed. Images will rarely be shown repeatedly.
smooth: height == preferredHeight && parent.height == parent.implicitHeight // Don't smooth until height animation stops smooth: height == preferredHeight && parent.height == parent.implicitHeight // Don't smooth until height animation stops
source: hasImage ? ChatBoxHelper.attachmentPath : "" source: hasImage ? chatBoxHelper.attachmentPath : ""
visible: hasImage visible: hasImage
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
@@ -162,14 +162,14 @@ Loader {
Component { Component {
id: imageEditorPage id: imageEditorPage
ImageEditorPage { ImageEditorPage {
imagePath: ChatBoxHelper.attachmentPath imagePath: chatBoxHelper.attachmentPath
} }
} }
onClicked: { onClicked: {
let imageEditor = applicationWindow().pageStack.layers.push(imageEditorPage); let imageEditor = applicationWindow().pageStack.layers.push(imageEditorPage);
imageEditor.newPathChanged.connect(function(newPath) { imageEditor.newPathChanged.connect(function(newPath) {
applicationWindow().pageStack.layers.pop(); applicationWindow().pageStack.layers.pop();
ChatBoxHelper.attachmentPath = newPath; chatBoxHelper.attachmentPath = newPath;
}); });
} }
ToolTip.text: text ToolTip.text: text
@@ -180,7 +180,7 @@ Loader {
icon.name: "dialog-cancel" icon.name: "dialog-cancel"
text: i18n("Cancel") text: i18n("Cancel")
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
onClicked: ChatBoxHelper.clearAttachment(); onClicked: chatBoxHelper.clearAttachment();
ToolTip.text: text ToolTip.text: text
ToolTip.visible: hovered ToolTip.visible: hovered
} }

View File

@@ -277,14 +277,14 @@ ToolBar {
} }
Item { Item {
visible: !ChatBoxHelper.isReplying && (!ChatBoxHelper.hasAttachment || uploadingBusySpinner.running) visible: !chatBoxHelper.isReplying && (!chatBoxHelper.hasAttachment || uploadingBusySpinner.running)
implicitWidth: uploadButton.implicitWidth implicitWidth: uploadButton.implicitWidth
implicitHeight: uploadButton.implicitHeight implicitHeight: uploadButton.implicitHeight
ToolButton { ToolButton {
id: uploadButton id: uploadButton
anchors.fill: parent anchors.fill: parent
// Matrix does not allow sending attachments in replies // Matrix does not allow sending attachments in replies
visible: !ChatBoxHelper.isReplying && !ChatBoxHelper.hasAttachment && !uploadingBusySpinner.running visible: !chatBoxHelper.isReplying && !chatBoxHelper.hasAttachment && !uploadingBusySpinner.running
icon.name: "mail-attachment" icon.name: "mail-attachment"
text: i18n("Attach an image or file") text: i18n("Attach an image or file")
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
@@ -296,7 +296,7 @@ ToolBar {
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay) var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
fileDialog.chosen.connect((path) => { fileDialog.chosen.connect((path) => {
if (!path) { return } if (!path) { return }
ChatBoxHelper.attachmentPath = path; chatBoxHelper.attachmentPath = path;
}) })
fileDialog.open() fileDialog.open()
} }
@@ -379,16 +379,16 @@ ToolBar {
if (!Clipboard.saveImage(localPath)) { if (!Clipboard.saveImage(localPath)) {
return; return;
} }
ChatBoxHelper.attachmentPath = localPath; chatBoxHelper.attachmentPath = localPath;
} }
function postMessage() { function postMessage() {
checkForFancyEffectsReason(); checkForFancyEffectsReason();
if (ChatBoxHelper.hasAttachment) { if (chatBoxHelper.hasAttachment) {
// send attachment but don't reset the text // send attachment but don't reset the text
actionsHandler.postMessage("", ChatBoxHelper.attachmentPath, actionsHandler.postMessage("", chatBoxHelper.attachmentPath,
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, {}, this.customEmojiModel); chatBoxHelper.replyEventId, chatBoxHelper.editEventId, {}, this.customEmojiModel);
currentRoom.markAllMessagesAsRead(); currentRoom.markAllMessagesAsRead();
messageSent(); messageSent();
return; return;
@@ -400,8 +400,8 @@ ToolBar {
actionsHandler.postEdit(inputField.text); actionsHandler.postEdit(inputField.text);
} else { } else {
// send normal message // send normal message
actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath, actionsHandler.postMessage(inputField.text.trim(), chatBoxHelper.attachmentPath,
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted, this.customEmojiModel); chatBoxHelper.replyEventId, chatBoxHelper.editEventId, userAutocompleted, this.customEmojiModel);
} }
currentRoom.markAllMessagesAsRead(); currentRoom.markAllMessagesAsRead();
inputField.clear(); inputField.clear();

View File

@@ -127,8 +127,8 @@ Item {
ReplyPane { ReplyPane {
id: replyPane id: replyPane
visible: ChatBoxHelper.isReplying || ChatBoxHelper.isEditing visible: chatBoxHelper.isReplying || chatBoxHelper.isEditing
user: ChatBoxHelper.replyUser user: chatBoxHelper.replyUser
width: parent.width width: parent.width
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
anchors.bottom: attachmentSeparator.top anchors.bottom: attachmentSeparator.top
@@ -154,7 +154,7 @@ Item {
AttachmentPane { AttachmentPane {
id: attachmentPane id: attachmentPane
visible: ChatBoxHelper.hasAttachment visible: chatBoxHelper.hasAttachment
width: parent.width width: parent.width
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
anchors.bottom: chatBarSeparator.top anchors.bottom: chatBarSeparator.top
@@ -248,7 +248,7 @@ Item {
} }
Connections { Connections {
target: ChatBoxHelper target: chatBoxHelper
function onShouldClearText() { function onShouldClearText() {
root.inputFieldText = ""; root.inputFieldText = "";
@@ -277,7 +277,7 @@ Item {
} }
function closeAll() { function closeAll() {
ChatBoxHelper.clear(); chatBoxHelper.clear();
chatBar.emojiPaneOpened = false; chatBar.emojiPaneOpened = false;
} }
} }

View File

@@ -12,7 +12,7 @@ import org.kde.neochat 1.0
Loader { Loader {
id: root id: root
readonly property bool isEdit: ChatBoxHelper.isEditing readonly property bool isEdit: chatBoxHelper.isEditing
property var user: null property var user: null
property string avatarMediaUrl: user ? "image://mxc/" + user.avatarMediaId : "" property string avatarMediaUrl: user ? "image://mxc/" + user.avatarMediaId : ""
@@ -83,7 +83,7 @@ Loader {
bottomPadding: 0 bottomPadding: 0
text: { text: {
const stylesheet = "<style> a{color:"+Kirigami.Theme.linkColor+";}.user-pill{}</style>"; const stylesheet = "<style> a{color:"+Kirigami.Theme.linkColor+";}.user-pill{}</style>";
const content = ChatBoxHelper.isReplying ? ChatBoxHelper.replyEventContent : ChatBoxHelper.editContent; const content = chatBoxHelper.isReplying ? chatBoxHelper.replyEventContent : chatBoxHelper.editContent;
return stylesheet + content; return stylesheet + content;
} }
selectByMouse: true selectByMouse: true
@@ -106,7 +106,7 @@ Loader {
text: i18n("Cancel") text: i18n("Cancel")
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
onClicked: { onClicked: {
ChatBoxHelper.clear(); chatBoxHelper.clear();
root.replyCancelled(); root.replyCancelled();
} }
ToolTip.text: text ToolTip.text: text

View File

@@ -50,7 +50,7 @@ MessageDelegateContextMenu {
text: i18n("Reply") text: i18n("Reply")
icon.name: "mail-replied-symbolic" icon.name: "mail-replied-symbolic"
onTriggered: { onTriggered: {
ChatBoxHelper.replyToMessage(eventId, message, author); chatBoxHelper.replyToMessage(eventId, message, author);
} }
}, },
Kirigami.Action { Kirigami.Action {

View File

@@ -28,13 +28,13 @@ Loader {
Kirigami.Action { Kirigami.Action {
text: i18n("Edit") text: i18n("Edit")
icon.name: "document-edit" icon.name: "document-edit"
onTriggered: ChatBoxHelper.edit(message, formattedBody, eventId); onTriggered: chatBoxHelper.edit(message, formattedBody, eventId);
visible: eventType.length > 0 && author.id === Controller.activeConnection.localUserId && (eventType === "emote" || eventType === "message") visible: eventType.length > 0 && author.id === Controller.activeConnection.localUserId && (eventType === "emote" || eventType === "message")
}, },
Kirigami.Action { Kirigami.Action {
text: i18n("Reply") text: i18n("Reply")
icon.name: "mail-replied-symbolic" icon.name: "mail-replied-symbolic"
onTriggered: ChatBoxHelper.replyToMessage(eventId, message, author); onTriggered: chatBoxHelper.replyToMessage(eventId, message, author);
}, },
Kirigami.Action { Kirigami.Action {
visible: author.id === currentRoom.localUser.id || currentRoom.canSendState("redact") visible: author.id === currentRoom.localUser.id || currentRoom.canSendState("redact")

View File

@@ -53,7 +53,7 @@ Kirigami.ScrollablePage {
onCurrentRoomChanged: { onCurrentRoomChanged: {
hasScrolledUpBefore = false; hasScrolledUpBefore = false;
ChatBoxHelper.clearEditReply() chatBoxHelper.clearEditReply()
} }
Connections { Connections {
@@ -81,6 +81,10 @@ Kirigami.ScrollablePage {
connection: Controller.activeConnection connection: Controller.activeConnection
} }
ChatBoxHelper {
id: chatBoxHelper
}
Shortcut { Shortcut {
sequence: StandardKey.Cancel sequence: StandardKey.Cancel
onActivated: applicationWindow().pageStack.get(0).forceActiveFocus() onActivated: applicationWindow().pageStack.get(0).forceActiveFocus()
@@ -262,7 +266,7 @@ Kirigami.ScrollablePage {
fileDialog.chosen.connect(function(path) { fileDialog.chosen.connect(function(path) {
if (!path) return if (!path) return
ChatBoxHelper.attachmentPath = path; chatBoxHelper.attachmentPath = path;
}) })
fileDialog.open() fileDialog.open()
@@ -284,7 +288,7 @@ Kirigami.ScrollablePage {
if (!Clipboard.saveImage(localPath)) { if (!Clipboard.saveImage(localPath)) {
return; return;
} }
ChatBoxHelper.attachmentPath = localPath; chatBoxHelper.attachmentPath = localPath;
attachDialog.close(); attachDialog.close();
} }
} }
@@ -359,7 +363,7 @@ Kirigami.ScrollablePage {
DropArea { DropArea {
id: dropAreaFile id: dropAreaFile
anchors.fill: parent anchors.fill: parent
onDropped: ChatBoxHelper.attachmentPath = drop.urls[0] onDropped: chatBoxHelper.attachmentPath = drop.urls[0]
} }
QQC2.Pane { QQC2.Pane {
@@ -486,7 +490,7 @@ Kirigami.ScrollablePage {
icon.name: "document-edit" icon.name: "document-edit"
onClicked: { onClicked: {
if (hoverActions.showEdit) { if (hoverActions.showEdit) {
ChatBoxHelper.edit(hoverActions.event.message, hoverActions.event.formattedBody, hoverActions.event.eventId) chatBoxHelper.edit(hoverActions.event.message, hoverActions.event.formattedBody, hoverActions.event.eventId)
} }
chatBox.focusInputField(); chatBox.focusInputField();
} }
@@ -496,7 +500,7 @@ Kirigami.ScrollablePage {
QQC2.ToolTip.visible: hovered QQC2.ToolTip.visible: hovered
icon.name: "mail-replied-symbolic" icon.name: "mail-replied-symbolic"
onClicked: { onClicked: {
ChatBoxHelper.replyToMessage(hoverActions.event.eventId, hoverActions.event.message, hoverActions.event.author); chatBoxHelper.replyToMessage(hoverActions.event.eventId, hoverActions.event.message, hoverActions.event.author);
chatBox.focusInputField(); chatBox.focusInputField();
} }
} }
@@ -516,14 +520,14 @@ Kirigami.ScrollablePage {
onEditLastUserMessage: { onEditLastUserMessage: {
const targetMessage = messageEventModel.getLastLocalUserMessageEventId(); const targetMessage = messageEventModel.getLastLocalUserMessageEventId();
if (targetMessage) { if (targetMessage) {
ChatBoxHelper.edit(targetMessage["message"], targetMessage["formattedBody"], targetMessage["event_id"]); chatBoxHelper.edit(targetMessage["message"], targetMessage["formattedBody"], targetMessage["event_id"]);
chatBox.focusInputField(); chatBox.focusInputField();
} }
} }
onReplyPreviousUserMessage: { onReplyPreviousUserMessage: {
const replyResponse = messageEventModel.getLatestMessageFromIndex(0); const replyResponse = messageEventModel.getLatestMessageFromIndex(0);
if (replyResponse && replyResponse["event_id"]) { if (replyResponse && replyResponse["event_id"]) {
ChatBoxHelper.replyToMessage(replyResponse["event_id"], replyResponse["message"], replyResponse["sender_id"]); chatBoxHelper.replyToMessage(replyResponse["event_id"], replyResponse["message"], replyResponse["sender_id"]);
} }
} }
} }

View File

@@ -195,13 +195,13 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "RoomManager", &RoomManager::instance()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "RoomManager", &RoomManager::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "ChatBoxHelper", &chatBoxHelper);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app)); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app)); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &spaceHierarchyCache); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &spaceHierarchyCache);
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler"); qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
qmlRegisterType<ChatBoxHelper>("org.kde.neochat", 1, 0, "ChatBoxHelper");
qmlRegisterType<ChatDocumentHandler>("org.kde.neochat", 1, 0, "ChatDocumentHandler"); qmlRegisterType<ChatDocumentHandler>("org.kde.neochat", 1, 0, "ChatDocumentHandler");
qmlRegisterType<RoomListModel>("org.kde.neochat", 1, 0, "RoomListModel"); qmlRegisterType<RoomListModel>("org.kde.neochat", 1, 0, "RoomListModel");
qmlRegisterType<KWebShortcutModel>("org.kde.neochat", 1, 0, "WebShortcutModel"); qmlRegisterType<KWebShortcutModel>("org.kde.neochat", 1, 0, "WebShortcutModel");