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.
This commit is contained in:
Joshua Goins
2025-09-02 18:42:34 -04:00
parent 9d8c9853ce
commit 409b6da160
3 changed files with 17 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
void testMaximizeMedia(); void testMaximizeMedia();
void testResolveMatrixLinks();
}; };
void RoomManagerTest::initTestCase() void RoomManagerTest::initTestCase()
@@ -128,5 +129,13 @@ void RoomManagerTest::testMaximizeMedia()
QVERIFY(spy[1][0] == 0); 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) QTEST_MAIN(RoomManagerTest)
#include "roommanagertest.moc" #include "roommanagertest.moc"

View File

@@ -66,7 +66,7 @@ Kirigami.Dialog {
text: i18nc("@action:button", "Join room") text: i18nc("@action:button", "Join room")
icon.name: "irc-join-channel" icon.name: "irc-join-channel"
onClicked: { onClicked: {
RoomManager.resolveResource(root.room, "join"); RoomManager.resolveResource(root.room, "join_confirmed");
root.close(); root.close();
} }
} }

View File

@@ -214,19 +214,23 @@ void RoomManager::resolveResource(Uri uri, const QString &action)
return; return;
} }
// For matrix URIs:
if (uri.type() != Uri::NonMatrix) { if (uri.type() != Uri::NonMatrix) {
if (!m_connection) { if (!m_connection) {
return; return;
} }
if (!action.isEmpty() && (uri.type() != Uri::UserId || action != "join"_L1)) { // Once a join is confirmed, set the action to "join" so it skips the confirmation check.
uri.setAction(action); if (action == "join_confirmed"_L1) {
uri.setAction(QStringLiteral("join"));
} }
// TODO we should allow the user to select a connection. // TODO we should allow the user to select a connection.
} }
const auto result = visitResource(m_connection, uri); const auto result = visitResource(m_connection, uri);
// If we are not already in the room:
if (result == Quotient::CouldNotResolve) { 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()); Q_EMIT askJoinRoom(uri.primaryId());
} }
} }