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:
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user