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.
This commit is contained in:
Tobias Fella
2021-04-16 16:52:39 +02:00
parent f98eb78185
commit 89056ed6c1
6 changed files with 16 additions and 13 deletions

View File

@@ -337,13 +337,13 @@ ToolBar {
checkForFancyEffectsReason(); checkForFancyEffectsReason();
if (ChatBoxHelper.hasAttachment) { if (ChatBoxHelper.hasAttachment) {
// send attachment but don't reset the text // send attachment but don't reset the text
roomManager.actionsHandler.postMessage("", ChatBoxHelper.attachmentPath, actionsHandler.postMessage("", ChatBoxHelper.attachmentPath,
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, {}); ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, {});
currentRoom.markAllMessagesAsRead(); currentRoom.markAllMessagesAsRead();
messageSent(); messageSent();
return; return;
} }
roomManager.actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath, actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath,
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted); ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted);
currentRoom.markAllMessagesAsRead(); currentRoom.markAllMessagesAsRead();
inputField.clear(); inputField.clear();

View File

@@ -36,7 +36,7 @@ Kirigami.OverlaySheet {
text: i18nc("@action:button", "Ok") text: i18nc("@action:button", "Ok")
onClicked: { onClicked: {
roomManager.actionsHandler.createRoom(roomNameField.text, roomTopicField.text); Controller.createRoom(roomNameField.text, roomTopicField.text);
root.close(); root.close();
root.destroy(); root.destroy();
} }

View File

@@ -44,7 +44,7 @@ Kirigami.ScrollablePage {
onClicked: { onClicked: {
if (!identifierField.isJoined) { if (!identifierField.isJoined) {
roomManager.actionsHandler.joinRoom(identifierField.text); Controller.joinRoom(identifierField.text);
// When joining the room, the room will be opened // When joining the room, the room will be opened
} }
applicationWindow().pageStack.layers.pop(); applicationWindow().pageStack.layers.pop();
@@ -97,7 +97,7 @@ Kirigami.ScrollablePage {
width: publicRoomsListView.width width: publicRoomsListView.width
onClicked: { onClicked: {
if (!isJoined) { if (!isJoined) {
roomManager.actionsHandler.joinRoom(roomID) Controller.joinRoom(roomID)
justJoined = true; justJoined = true;
} else { } else {
roomManager.enterRoom(connection.room(roomID)) roomManager.enterRoom(connection.room(roomID))

View File

@@ -30,6 +30,14 @@ Kirigami.ScrollablePage {
onCurrentRoomChanged: ChatBoxHelper.clearEditReply() onCurrentRoomChanged: ChatBoxHelper.clearEditReply()
ActionsHandler {
id: actionsHandler
room: page.currentRoom
connection: Controller.activeConnection
}
Connections { Connections {
target: Controller.activeConnection target: Controller.activeConnection
function onJoinedRoom(room) { function onJoinedRoom(room) {
@@ -40,7 +48,7 @@ Kirigami.ScrollablePage {
} }
Connections { Connections {
target: roomManager.actionsHandler target: actionsHandler
onShowMessage: { onShowMessage: {
page.header.contentItem.text = message; page.header.contentItem.text = message;
page.header.contentItem.type = messageType === ActionsHandler.Error ? Kirigami.MessageType.Error : Kirigami.MessageType.Information; page.header.contentItem.type = messageType === ActionsHandler.Error ? Kirigami.MessageType.Error : Kirigami.MessageType.Information;

View File

@@ -57,11 +57,6 @@ Kirigami.ApplicationWindow {
QtObject { QtObject {
id: roomManager id: roomManager
property var actionsHandler: ActionsHandler {
room: roomManager.currentRoom
connection: Controller.activeConnection
}
property var currentRoom: null property var currentRoom: null
property alias pageStack: root.pageStack property alias pageStack: root.pageStack
property var roomList: null property var roomList: null

View File

@@ -73,10 +73,10 @@ public:
Q_ENUM(PasswordStatus); Q_ENUM(PasswordStatus);
/// \brief Create new room for a group chat. /// \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. /// \brief Join a room.
void joinRoom(const QString &alias); Q_INVOKABLE void joinRoom(const QString &alias);
private: private:
explicit Controller(QObject *parent = nullptr); explicit Controller(QObject *parent = nullptr);