diff --git a/src/models/actionsmodel.cpp b/src/models/actionsmodel.cpp index c6384ec1f..eeb1ab85f 100644 --- a/src/models/actionsmodel.cpp +++ b/src/models/actionsmodel.cpp @@ -230,7 +230,7 @@ QList actions{ } auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text); if (targetRoom) { - RoomManager::instance().enterRoom(dynamic_cast(targetRoom)); + RoomManager::instance().resolveResource(targetRoom->id()); return QString(); } Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("Joining room .", "Joining room %1.", text)); @@ -256,7 +256,7 @@ QList actions{ } auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text); if (targetRoom) { - RoomManager::instance().enterRoom(dynamic_cast(targetRoom)); + RoomManager::instance().resolveResource(targetRoom->id()); return QString(); } Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("Knocking room .", "Knocking room %1.", text)); diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 5da6eba60..0a02e47f7 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -240,7 +240,7 @@ void NeoChatConnection::createRoom(const QString &name, const QString &topic, co Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {}); }); connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { - RoomManager::instance().enterRoom(dynamic_cast(room)); + RoomManager::instance().resolveResource(room->id()); }); } @@ -272,7 +272,7 @@ void NeoChatConnection::createSpace(const QString &name, const QString &topic, c Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {}); }); connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { - RoomManager::instance().enterRoom(dynamic_cast(room)); + RoomManager::instance().resolveResource(room->id()); }); } @@ -295,9 +295,9 @@ void NeoChatConnection::openOrCreateDirectChat(User *user) const auto existing = directChats(); if (existing.contains(user)) { - const auto room = static_cast(this->room(existing.value(user))); + const auto room = this->room(existing.value(user)); if (room) { - RoomManager::instance().enterRoom(room); + RoomManager::instance().resolveResource(room->id()); return; } } diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index ce5f788f1..9dd5dadfb 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -216,7 +216,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room, auto connection = dynamic_cast(Controller::instance().accounts().get(room->localUser()->id())); Controller::instance().setActiveConnection(connection); RoomManager::instance().setConnection(connection); - RoomManager::instance().enterRoom(room); + RoomManager::instance().resolveResource(room->id()); }); if (canReply) { @@ -251,7 +251,7 @@ void NotificationsManager::postInviteNotification(NeoChatRoom *rawRoom, const QS } WindowController::instance().showAndRaiseWindow(notification->xdgActivationToken()); notification->close(); - RoomManager::instance().enterRoom(room); + RoomManager::instance().resolveResource(room->id()); }); const auto acceptAction = notification->addAction(i18nc("@action:button The thing being accepted is an invitation to chat", "Accept")); diff --git a/src/qml/CollapsedRoomDelegate.qml b/src/qml/CollapsedRoomDelegate.qml index 0df4e721c..bd994867a 100644 --- a/src/qml/CollapsedRoomDelegate.qml +++ b/src/qml/CollapsedRoomDelegate.qml @@ -42,10 +42,10 @@ QQC2.ItemDelegate { } } - onClicked: RoomManager.enterRoom(root.currentRoom) + onClicked: RoomManager.resolveResource(currentRoom.id) - Keys.onEnterPressed: RoomManager.enterRoom(root.currentRoom) - Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom) + Keys.onEnterPressed: RoomManager.resolveResource(currentRoom.id) + Keys.onReturnPressed: RoomManager.resolveResource(currentRoom.id) QQC2.ToolTip.visible: text.length > 0 && hovered QQC2.ToolTip.text: root.displayName ?? "" diff --git a/src/qml/ExploreComponent.qml b/src/qml/ExploreComponent.qml index 9eae69887..973b3c76d 100644 --- a/src/qml/ExploreComponent.qml +++ b/src/qml/ExploreComponent.qml @@ -23,11 +23,7 @@ RowLayout { onTriggered: { let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")}) dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { - if (isJoined) { - RoomManager.enterRoom(root.connection.room(roomId)) - } else { - RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, "join") - } + RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join") }) } } diff --git a/src/qml/ExploreComponentMobile.qml b/src/qml/ExploreComponentMobile.qml index 507face73..fd5c213d4 100644 --- a/src/qml/ExploreComponentMobile.qml +++ b/src/qml/ExploreComponentMobile.qml @@ -54,11 +54,7 @@ ColumnLayout { onTriggered: { let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")}) dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { - if (isJoined) { - RoomManager.enterRoom(root.connection.room(roomId)); - } else { - RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, "join"); - } + RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join") }) exploreTabBar.currentIndex = -1; } diff --git a/src/qml/General.qml b/src/qml/General.qml index a3a106ebe..762e28bc8 100644 --- a/src/qml/General.qml +++ b/src/qml/General.qml @@ -373,7 +373,7 @@ FormCard.FormCardPage { actions: Kirigami.Action { text: i18n("See older messages…") onTriggered: { - RoomManager.enterRoom(root.connection.room(room.predecessorId)); + RoomManager.resolveResource(room.predecessorId); root.close(); } } @@ -387,7 +387,7 @@ FormCard.FormCardPage { actions: Kirigami.Action { text: i18n("See new room…") onTriggered: { - RoomManager.enterRoom(root.connection.room(room.successorId)); + RoomManager.resolveResource(room.successorId); root.close(); } } diff --git a/src/qml/GlobalMenu.qml b/src/qml/GlobalMenu.qml index b796632b6..1966582bc 100644 --- a/src/qml/GlobalMenu.qml +++ b/src/qml/GlobalMenu.qml @@ -63,11 +63,7 @@ Labs.MenuBar { onTriggered: { let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")}) dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { - if (isJoined) { - RoomManager.enterRoom(root.connection.room(roomId)) - } else { - RoomManager.resolveResource(roomId, "join") - } + RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join") }) } } diff --git a/src/qml/QuickSwitcher.qml b/src/qml/QuickSwitcher.qml index e372a9293..8e2a666bc 100644 --- a/src/qml/QuickSwitcher.qml +++ b/src/qml/QuickSwitcher.qml @@ -59,11 +59,11 @@ QQC2.Dialog { } } Keys.onEnterPressed: { - RoomManager.enterRoom(roomList.currentItem.currentRoom); + RoomManager.resolveResource(roomList.currentItem.currentRoom.id); root.close(); } Keys.onReturnPressed: { - RoomManager.enterRoom(roomList.currentItem.currentRoom); + RoomManager.resolveResource(roomList.currentItem.currentRoom.id); root.close(); } focusSequence: "" @@ -92,23 +92,8 @@ QQC2.Dialog { delegate: RoomDelegate { filterText: searchField.text - connection: root.connection - - onSelected: { - RoomManager.enterRoom(currentRoom); - root.close() - } - - Keys.onEnterPressed: { - RoomManager.enterRoom(currentRoom); - root.close(); - } - - Keys.onReturnPressed: { - RoomManager.enterRoom(currentRoom); - root.close(); - } + onSelected: root.close() } } } diff --git a/src/qml/RoomDelegate.qml b/src/qml/RoomDelegate.qml index 3b2083567..1acead9f3 100644 --- a/src/qml/RoomDelegate.qml +++ b/src/qml/RoomDelegate.qml @@ -34,19 +34,21 @@ Delegates.RoundedItemDelegate { signal selected() Accessible.name: root.displayName - Accessible.onPressAction: selected() - Keys.onSpacePressed: selected() - Keys.onEnterPressed: selected() + Accessible.onPressAction: select() onPressAndHold: createRoomListContextMenu() + Keys.onSpacePressed: select() + Keys.onEnterPressed: select() + Keys.onReturnPressed: select() + TapHandler { acceptedButtons: Qt.RightButton | Qt.LeftButton onTapped: (eventPoint, button) => { if (button === Qt.RightButton) { root.createRoomListContextMenu(); } else { - root.selected(); + select() } } } @@ -145,6 +147,11 @@ Delegates.RoundedItemDelegate { } } + function select() { + RoomManager.resolveResource(currentRoom.id); + root.selected() + } + function createRoomListContextMenu() { const component = Qt.createComponent("qrc:/org/kde/neochat/qml/ContextMenu.qml") if (component.status === Component.Error) { diff --git a/src/qml/RoomListPage.qml b/src/qml/RoomListPage.qml index 7c40ceaa7..1134514c1 100644 --- a/src/qml/RoomListPage.qml +++ b/src/qml/RoomListPage.qml @@ -179,11 +179,7 @@ Kirigami.Page { title: i18nc("@title", "Explore Rooms") }) dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { - if (isJoined) { - RoomManager.enterRoom(root.connection.room(roomId)) - } else { - RoomManager.resolveResource(roomId, "join") - } + RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join") }) } } @@ -294,11 +290,6 @@ Kirigami.Page { height: visible ? implicitHeight : 0 visible: categoryVisible || filterText.length > 0 - - onSelected: RoomManager.enterRoom(currentRoom) - - Keys.onEnterPressed: RoomManager.enterRoom(currentRoom) - Keys.onReturnPressed: RoomManager.enterRoom(currentRoom) } } diff --git a/src/qml/RoomPage.qml b/src/qml/RoomPage.qml index 737e16625..c0e64e8fb 100644 --- a/src/qml/RoomPage.qml +++ b/src/qml/RoomPage.qml @@ -206,7 +206,7 @@ Kirigami.Page { target: root.connection function onJoinedRoom(room, invited) { if(root.currentRoom.id === invited.id) { - RoomManager.enterRoom(room); + RoomManager.resolveResource(room.id); } } } diff --git a/src/qml/SpaceHierarchyDelegate.qml b/src/qml/SpaceHierarchyDelegate.qml index afa3e9abb..32f756024 100644 --- a/src/qml/SpaceHierarchyDelegate.qml +++ b/src/qml/SpaceHierarchyDelegate.qml @@ -34,7 +34,6 @@ Item { required property NeoChatRoom parentRoom signal createRoom() - signal enterRoom() Delegates.RoundedItemDelegate { anchors.centerIn: root @@ -146,11 +145,7 @@ Item { if (root.isSpace) { root.treeView.toggleExpanded(row) } else { - if (root.isJoined) { - root.enterRoom() - } else { - RoomManager.resolveResource(root.roomId, "join") - } + RoomManager.resolveResource(root.roomId, root.isJoined ? "" : "join") } } } diff --git a/src/qml/SpaceHomePage.qml b/src/qml/SpaceHomePage.qml index 9dfa2b73a..346e81099 100644 --- a/src/qml/SpaceHomePage.qml +++ b/src/qml/SpaceHomePage.qml @@ -117,7 +117,6 @@ Kirigami.Page { delegate: SpaceHierarchyDelegate { onCreateRoom: _private.createRoom(roomId) - onEnterRoom: _private.enterRoom(roomId) } } @@ -167,12 +166,5 @@ Kirigami.Page { }) dialog.newChild.connect(childName => {spaceChildrenModel.addPendingChild(childName)}) } - - function enterRoom(roomId) { - let room = root.currentRoom.connection.room(roomId) - if (room) { - RoomManager.enterRoom(room) - } - } } } diff --git a/src/qml/SpaceListContextMenu.qml b/src/qml/SpaceListContextMenu.qml index 0df44c1d3..c08dc561c 100644 --- a/src/qml/SpaceListContextMenu.qml +++ b/src/qml/SpaceListContextMenu.qml @@ -29,7 +29,7 @@ Loader { QQC2.MenuItem { text: i18nc("'Space' is a matrix space", "View Space") icon.name: "view-list-details" - onTriggered: RoomManager.enterSpaceHome(room); + onTriggered: RoomManager.resolveResource(room.id); } QQC2.MenuItem { @@ -109,7 +109,7 @@ Loader { FormCard.FormButtonDelegate { text: i18nc("'Space' is a matrix space", "View Space") icon.name: "view-list-details" - onClicked: RoomManager.enterRoom(room); + onClicked: RoomManager.resolveResource(root.room.id); } FormCard.FormButtonDelegate { diff --git a/src/qml/main.qml b/src/qml/main.qml index 402023006..e3d8eb659 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -326,7 +326,7 @@ Kirigami.ApplicationWindow { target: root.connection function onDirectChatAvailable(directChat) { - RoomManager.enterRoom(root.connection.room(directChat.id)); + RoomManager.resolveResource(directChat.id); } function onNewKeyVerificationSession(session) { applicationWindow().pageStack.pushDialogLayer(keyVerificationDialogComponent, { diff --git a/src/roommanager.cpp b/src/roommanager.cpp index ddf6992dd..029bec00c 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -102,7 +102,7 @@ void RoomManager::resolveResource(const QString &idOrUri, const QString &action) if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) { connectSingleShot(m_connection, &Connection::newRoom, this, [this, uri](Room *room) { - enterRoom(dynamic_cast(room)); + resolveResource(room->id()); }); } } @@ -191,82 +191,17 @@ void RoomManager::openRoomForActiveConnection() const auto room = qobject_cast(m_connection->room(roomId)); if (room) { - if (room->isSpace()) { - enterSpaceHome(room); - } else { - enterRoom(room); - } + resolveResource(room->id()); } } } -void RoomManager::enterRoom(NeoChatRoom *room) -{ - if (m_currentRoom && !m_currentRoom->editCache()->editId().isEmpty()) { - m_currentRoom->editCache()->setEditId({}); - } - if (m_currentRoom && m_chatDocumentHandler) { - // We're doing these things here because it is critical that they are switched at the same time - if (m_chatDocumentHandler->document()) { - m_currentRoom->mainCache()->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); - m_chatDocumentHandler->setRoom(room); - m_chatDocumentHandler->document()->textDocument()->setPlainText(room->mainCache()->savedText()); - room->mainCache()->setText(room->mainCache()->savedText()); - } else { - m_chatDocumentHandler->setRoom(room); - } - } - m_lastCurrentRoom = std::exchange(m_currentRoom, room); - Q_EMIT currentRoomChanged(); - - if (!m_lastCurrentRoom) { - Q_EMIT pushRoom(room, QString()); - } else { - Q_EMIT replaceRoom(m_currentRoom, QString()); - } - - if (room && room->timelineSize() == 0) { - room->getPreviousContent(20); - } - - // Save last open room - m_lastRoomConfig.writeEntry(m_connection->userId(), room->id()); -} - void RoomManager::openWindow(NeoChatRoom *room) { // forward the call to QML Q_EMIT openRoomInNewWindow(room); } -void RoomManager::enterSpaceHome(NeoChatRoom *spaceRoom) -{ - if (!spaceRoom->isSpace()) { - return; - } - // If replacing a normal room message timeline make sure any edit is cancelled. - if (m_currentRoom && !m_currentRoom->editCache()->editId().isEmpty()) { - m_currentRoom->editCache()->setEditId({}); - } - // Save the chatbar text for the current room if any before switching - if (m_currentRoom && m_chatDocumentHandler) { - if (m_chatDocumentHandler->document()) { - m_currentRoom->mainCache()->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); - } - } - m_lastCurrentRoom = std::exchange(m_currentRoom, spaceRoom); - Q_EMIT currentRoomChanged(); - - if (!m_lastCurrentRoom) { - Q_EMIT pushSpaceHome(spaceRoom); - } else { - Q_EMIT replaceSpaceHome(m_currentRoom); - } - - // Save last open room - m_lastRoomConfig.writeEntry(m_connection->userId(), spaceRoom->id()); -} - UriResolveResult RoomManager::visitUser(User *user, const QString &action) { if (action == "mention"_ls || action.isEmpty()) { @@ -290,19 +225,46 @@ void RoomManager::visitRoom(Room *room, const QString &eventId) auto neoChatRoom = qobject_cast(room); Q_ASSERT(neoChatRoom != nullptr); + if (m_currentRoom && !m_currentRoom->editCache()->editId().isEmpty()) { + m_currentRoom->editCache()->setEditId({}); + } + if (m_currentRoom && !m_currentRoom->isSpace() && m_chatDocumentHandler) { + // We're doing these things here because it is critical that they are switched at the same time + if (m_chatDocumentHandler->document()) { + m_currentRoom->mainCache()->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); + m_chatDocumentHandler->setRoom(neoChatRoom); + m_chatDocumentHandler->document()->textDocument()->setPlainText(neoChatRoom->mainCache()->savedText()); + neoChatRoom->mainCache()->setText(neoChatRoom->mainCache()->savedText()); + } else { + m_chatDocumentHandler->setRoom(neoChatRoom); + } + } + if (m_currentRoom) { if (m_currentRoom->id() == room->id()) { Q_EMIT goToEvent(eventId); } else { m_lastCurrentRoom = std::exchange(m_currentRoom, neoChatRoom); Q_EMIT currentRoomChanged(); - Q_EMIT replaceRoom(neoChatRoom, eventId); + + if (neoChatRoom->isSpace()) { + Q_EMIT replaceSpaceHome(neoChatRoom); + } else { + Q_EMIT replaceRoom(neoChatRoom, eventId); + } } } else { m_lastCurrentRoom = std::exchange(m_currentRoom, neoChatRoom); Q_EMIT currentRoomChanged(); - Q_EMIT pushRoom(neoChatRoom, eventId); + if (neoChatRoom->isSpace()) { + Q_EMIT pushSpaceHome(neoChatRoom); + } else { + Q_EMIT pushRoom(neoChatRoom, eventId); + } } + + // Save last open room + m_lastRoomConfig.writeEntry(m_connection->userId(), room->id()); } void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QStringList &viaServers) @@ -311,7 +273,7 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli connectSingleShot(job, &Quotient::BaseJob::finished, this, [this, account](Quotient::BaseJob *finish) { if (finish->status() == Quotient::BaseJob::Success) { connectSingleShot(account, &Quotient::Connection::newRoom, this, [this](Quotient::Room *room) { - enterRoom(dynamic_cast(room)); + resolveResource(room->id()); }); } else { Q_EMIT warning(i18n("Failed to join room"), finish->errorString()); diff --git a/src/roommanager.h b/src/roommanager.h index 12cbb1648..3ade35567 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -136,13 +136,6 @@ public: */ Q_INVOKABLE void loadInitialRoom(); - /** - * @brief Enter the given room. - * - * This method will tell NeoChat to open the message list with the given room. - */ - Q_INVOKABLE void enterRoom(NeoChatRoom *room); - /** * @brief Open a new window with the given room. * @@ -155,13 +148,6 @@ public: */ Q_INVOKABLE void leaveRoom(NeoChatRoom *room); - /** - * @brief Enter the home page of the given space. - * - * This method will tell NeoChat to open the home page for the given space. - */ - Q_INVOKABLE void enterSpaceHome(NeoChatRoom *spaceRoom); - /** * @brief Knock a room. * diff --git a/src/runner.cpp b/src/runner.cpp index bef32b917..41cad0eb9 100644 --- a/src/runner.cpp +++ b/src/runner.cpp @@ -85,14 +85,7 @@ void Runner::Run(const QString &id, const QString &actionId) { Q_UNUSED(actionId); - NeoChatRoom *room = qobject_cast(roomListModel()->connection()->room(id)); - - if (!room) { - return; - } - - RoomManager::instance().enterRoom(room); - + RoomManager::instance().resolveResource(id); WindowController::instance().showAndRaiseWindow(QString()); }