From 89056ed6c14be263ad77162c7a86c5ed638688c4 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 16 Apr 2021 16:52:39 +0200 Subject: [PATCH] Move the ActionsHandler instance to the RoomPage This is required since when using a RoomWindow, the ActionsHandler from the RoomManager is used, which means that the wrong room is used. --- imports/NeoChat/Component/ChatBox/ChatBar.qml | 4 ++-- imports/NeoChat/Dialog/CreateRoomDialog.qml | 2 +- imports/NeoChat/Page/JoinRoomPage.qml | 4 ++-- imports/NeoChat/Page/RoomPage.qml | 10 +++++++++- qml/main.qml | 5 ----- src/controller.h | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/imports/NeoChat/Component/ChatBox/ChatBar.qml b/imports/NeoChat/Component/ChatBox/ChatBar.qml index 572f85fb9..80d68d801 100644 --- a/imports/NeoChat/Component/ChatBox/ChatBar.qml +++ b/imports/NeoChat/Component/ChatBox/ChatBar.qml @@ -337,13 +337,13 @@ ToolBar { checkForFancyEffectsReason(); if (ChatBoxHelper.hasAttachment) { // send attachment but don't reset the text - roomManager.actionsHandler.postMessage("", ChatBoxHelper.attachmentPath, + actionsHandler.postMessage("", ChatBoxHelper.attachmentPath, ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, {}); currentRoom.markAllMessagesAsRead(); messageSent(); return; } - roomManager.actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath, + actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath, ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted); currentRoom.markAllMessagesAsRead(); inputField.clear(); diff --git a/imports/NeoChat/Dialog/CreateRoomDialog.qml b/imports/NeoChat/Dialog/CreateRoomDialog.qml index 396a031d3..aa9225cfb 100644 --- a/imports/NeoChat/Dialog/CreateRoomDialog.qml +++ b/imports/NeoChat/Dialog/CreateRoomDialog.qml @@ -36,7 +36,7 @@ Kirigami.OverlaySheet { text: i18nc("@action:button", "Ok") onClicked: { - roomManager.actionsHandler.createRoom(roomNameField.text, roomTopicField.text); + Controller.createRoom(roomNameField.text, roomTopicField.text); root.close(); root.destroy(); } diff --git a/imports/NeoChat/Page/JoinRoomPage.qml b/imports/NeoChat/Page/JoinRoomPage.qml index 385919a7b..a47cc3e98 100644 --- a/imports/NeoChat/Page/JoinRoomPage.qml +++ b/imports/NeoChat/Page/JoinRoomPage.qml @@ -44,7 +44,7 @@ Kirigami.ScrollablePage { onClicked: { if (!identifierField.isJoined) { - roomManager.actionsHandler.joinRoom(identifierField.text); + Controller.joinRoom(identifierField.text); // When joining the room, the room will be opened } applicationWindow().pageStack.layers.pop(); @@ -97,7 +97,7 @@ Kirigami.ScrollablePage { width: publicRoomsListView.width onClicked: { if (!isJoined) { - roomManager.actionsHandler.joinRoom(roomID) + Controller.joinRoom(roomID) justJoined = true; } else { roomManager.enterRoom(connection.room(roomID)) diff --git a/imports/NeoChat/Page/RoomPage.qml b/imports/NeoChat/Page/RoomPage.qml index c5e091e02..57a58499c 100644 --- a/imports/NeoChat/Page/RoomPage.qml +++ b/imports/NeoChat/Page/RoomPage.qml @@ -30,6 +30,14 @@ Kirigami.ScrollablePage { onCurrentRoomChanged: ChatBoxHelper.clearEditReply() + + ActionsHandler { + id: actionsHandler + room: page.currentRoom + connection: Controller.activeConnection + } + + Connections { target: Controller.activeConnection function onJoinedRoom(room) { @@ -40,7 +48,7 @@ Kirigami.ScrollablePage { } Connections { - target: roomManager.actionsHandler + target: actionsHandler onShowMessage: { page.header.contentItem.text = message; page.header.contentItem.type = messageType === ActionsHandler.Error ? Kirigami.MessageType.Error : Kirigami.MessageType.Information; diff --git a/qml/main.qml b/qml/main.qml index 402ff6c1b..677f4a350 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -57,11 +57,6 @@ Kirigami.ApplicationWindow { QtObject { id: roomManager - property var actionsHandler: ActionsHandler { - room: roomManager.currentRoom - connection: Controller.activeConnection - } - property var currentRoom: null property alias pageStack: root.pageStack property var roomList: null diff --git a/src/controller.h b/src/controller.h index 023981fbf..b285bf402 100644 --- a/src/controller.h +++ b/src/controller.h @@ -73,10 +73,10 @@ public: Q_ENUM(PasswordStatus); /// \brief Create new room for a group chat. - void createRoom(const QString &name, const QString &topic); + Q_INVOKABLE void createRoom(const QString &name, const QString &topic); /// \brief Join a room. - void joinRoom(const QString &alias); + Q_INVOKABLE void joinRoom(const QString &alias); private: explicit Controller(QObject *parent = nullptr);