Page MenuHomePhorge

D218.1752490221.diff
No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None

D218.1752490221.diff

diff --git a/src/matrix-link.cpp b/src/matrix-link.cpp
--- a/src/matrix-link.cpp
+++ b/src/matrix-link.cpp
@@ -37,6 +37,21 @@
return q.allQueryItemValues(u"via"_s);
}
+std::pair<MatrixLink::Type, QString> parseMatrixSchemeComp(
+ const QString &type, const QString &id) {
+ if (type == u"u"_s) {
+ return {MatrixLink::User, u"@"_s + id};
+ } else if (type == u"r"_s) {
+ return {MatrixLink::RoomAlias, u"#"_s + id};
+ } else if (type == u"roomid"_s) {
+ return {MatrixLink::RoomId, u"!"_s + id};
+ } else if (type == u"e"_s) {
+ return {MatrixLink::Event, u"$"_s + id};
+ } else {
+ return {MatrixLink::None, id};
+ }
+}
+
MatrixLink::MatrixLink(const QUrl &url)
{
// matrix.to link
@@ -56,6 +71,20 @@
m_identifiers.push_back(parseMatrixToComp(comp));
}
+ m_routingServers = parseMatrixToQuery(query);
+ } else if (url.scheme() == u"matrix"_s) { // Matrix URI scheme
+ auto path = url.path();
+ auto query = url.query();
+ auto segments = path.split(u'/');
+ if (segments.size() != 2 && segments.size() != 4) {
+ return;
+ }
+ m_identifiers.push_back(
+ parseMatrixSchemeComp(segments[0], segments[1]));
+ if (segments.size() == 4) {
+ m_identifiers.push_back(
+ parseMatrixSchemeComp(segments[2], segments[3]));
+ }
m_routingServers = parseMatrixToQuery(query);
}
}
diff --git a/src/tests/matrix-link-test.cpp b/src/tests/matrix-link-test.cpp
--- a/src/tests/matrix-link-test.cpp
+++ b/src/tests/matrix-link-test.cpp
@@ -35,6 +35,12 @@
QUrl(u"http://matrix.to/#/%40alice%3Aexample.org"_s),
QUrl(u"https://lol.lol/#/%40alice%3Aexample.org"_s),
QUrl(u"https://matrix.to/#%40alice%3Aexample.org"_s),
+ QUrl(u"matrix:/"_s),
+ QUrl(u"matrix://"_s),
+ QUrl(u"matrix:///"_s),
+ QUrl(u"matrix:r"_s),
+ QUrl(u"matrix:r/somewhere:example.org/e"_s),
+ QUrl(u"matrix:r/somewhere:example.org/e/event/e"_s),
};
for (auto link : links) {
MatrixLink ml(link);
@@ -49,6 +55,7 @@
QUrl(u"https://matrix.to/#/@alice%3Aexample.org"_s),
QUrl(u"https://matrix.to/#/%40alice:example.org"_s),
QUrl(u"https://matrix.to/#/@alice:example.org"_s),
+ QUrl(u"matrix:u/alice:example.org"_s),
};
for (auto link : links) {
MatrixLink ml(link);
@@ -68,6 +75,8 @@
{QUrl(u"https://matrix.to/#/!somewhere:example.org?via=elsewhere.ca"_s), u"!somewhere:example.org"_s},
{QUrl(u"https://matrix.to/#/!somewhere%3Aexample.org"_s), u"!somewhere:example.org"_s},
{QUrl(u"https://matrix.to/#/!somewhere:example.org"_s), u"!somewhere:example.org"_s},
+ {QUrl(u"matrix:r/somewhere:example.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"matrix:roomid/somewhere:example.org"_s), u"!somewhere:example.org"_s},
};
for (auto [link, pointed] : links) {
MatrixLink ml(link);
@@ -83,6 +92,8 @@
{QUrl(u"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org"_s), u"#somewhere:example.org"_s},
{QUrl(u"https://matrix.to/#/!somewhere%3Aexample.org/%24event%3Aexample.org?via=elsewhere.ca"_s), u"!somewhere:example.org"_s},
{QUrl(u"https://matrix.to/#/!somewhere%3Aexample.org/$event:example.org?via=elsewhere.ca"_s), u"!somewhere:example.org"_s},
+ {QUrl(u"matrix:r/somewhere:example.org/e/event:example.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"matrix:roomid/somewhere:example.org/e/event:example.org"_s), u"!somewhere:example.org"_s},
};
for (auto [link, pointed] : links) {
MatrixLink ml(link);
@@ -100,6 +111,14 @@
QCOMPARE(MatrixLink(QUrl(u"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org?via=a.org&via=b.org"_s)).routingServers(), (QStringList{u"a.org"_s, u"b.org"_s}));
QCOMPARE(MatrixLink(QUrl(u"https://matrix.to/#/%23somewhere%3Aexample.org/%24event:example.org?foo=bar&via=a.org&via=b.org"_s)).routingServers(), (QStringList{u"a.org"_s, u"b.org"_s}));
+
+ QCOMPARE(MatrixLink(QUrl(u"matrix:r/somewhere:example.org/e/event:example.org"_s)).routingServers(), (QStringList{}));
+
+ QCOMPARE(MatrixLink(QUrl(u"matrix:r/somewhere:example.org/e/event:example.org?via=a.org"_s)).routingServers(), (QStringList{u"a.org"_s}));
+
+ QCOMPARE(MatrixLink(QUrl(u"matrix:r/somewhere:example.org/e/event:example.org?via=a.org&via=b.org"_s)).routingServers(), (QStringList{u"a.org"_s, u"b.org"_s}));
+
+ QCOMPARE(MatrixLink(QUrl(u"matrix:r/somewhere:example.org/e/event:example.org?foo=bar&via=a.org&via=b.org"_s)).routingServers(), (QStringList{u"a.org"_s, u"b.org"_s}));
}
QTEST_MAIN(MatrixLinkTest)

File Metadata

Mime Type
text/plain
Expires
Mon, Jul 14, 3:50 AM (13 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
257708
Default Alt Text
D218.1752490221.diff (4 KB)

Event Timeline