From 409b6da160924a7c2b12c959ca81597a3a9a202c Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 2 Sep 2025 18:42:34 -0400 Subject: [PATCH] Bring up the room confirmation dialog in more situations This super helpful and nice dialog went mostly unused, especially if you only joined links to rooms through matrix.to or within NeoChat itself. The reason why this never showed up for said links is because we were greedily overwriting the "action". I don't think the code made solid sense anyway, so I redone it a bit so there's a clearer "join_confirmed" our UI uses. I added a test case to showcase this working. --- autotests/roommanagertest.cpp | 9 +++++++++ src/app/qml/JoinRoomDialog.qml | 2 +- src/app/roommanager.cpp | 10 +++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/autotests/roommanagertest.cpp b/autotests/roommanagertest.cpp index f2962967a..3f1e1571c 100644 --- a/autotests/roommanagertest.cpp +++ b/autotests/roommanagertest.cpp @@ -28,6 +28,7 @@ private: private Q_SLOTS: void initTestCase(); void testMaximizeMedia(); + void testResolveMatrixLinks(); }; void RoomManagerTest::initTestCase() @@ -128,5 +129,13 @@ void RoomManagerTest::testMaximizeMedia() QVERIFY(spy[1][0] == 0); } +void RoomManagerTest::testResolveMatrixLinks() +{ + // Test if resolving a non-joined room will bring up the confirmation dialog. + const QSignalSpy askToJoinSpy(&RoomManager::instance(), &RoomManager::askJoinRoom); + RoomManager::instance().resolveResource(QStringLiteral("matrix:r/testbuild:matrix.org"), QStringLiteral("join")); + QTRY_COMPARE(askToJoinSpy.size(), 1); +} + QTEST_MAIN(RoomManagerTest) #include "roommanagertest.moc" diff --git a/src/app/qml/JoinRoomDialog.qml b/src/app/qml/JoinRoomDialog.qml index cce6de31f..7fc52313b 100644 --- a/src/app/qml/JoinRoomDialog.qml +++ b/src/app/qml/JoinRoomDialog.qml @@ -66,7 +66,7 @@ Kirigami.Dialog { text: i18nc("@action:button", "Join room") icon.name: "irc-join-channel" onClicked: { - RoomManager.resolveResource(root.room, "join"); + RoomManager.resolveResource(root.room, "join_confirmed"); root.close(); } } diff --git a/src/app/roommanager.cpp b/src/app/roommanager.cpp index 55cc58d91..f77fc1e79 100644 --- a/src/app/roommanager.cpp +++ b/src/app/roommanager.cpp @@ -214,19 +214,23 @@ void RoomManager::resolveResource(Uri uri, const QString &action) return; } + // For matrix URIs: if (uri.type() != Uri::NonMatrix) { if (!m_connection) { return; } - if (!action.isEmpty() && (uri.type() != Uri::UserId || action != "join"_L1)) { - uri.setAction(action); + // Once a join is confirmed, set the action to "join" so it skips the confirmation check. + if (action == "join_confirmed"_L1) { + uri.setAction(QStringLiteral("join")); } // TODO we should allow the user to select a connection. } const auto result = visitResource(m_connection, uri); + + // If we are not already in the room: if (result == Quotient::CouldNotResolve) { - if ((uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) && action != "no_join"_L1) { + if ((uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) && action == "join"_L1) { Q_EMIT askJoinRoom(uri.primaryId()); } }