Page MenuHomePhorge

D218.1749463259.diff
No OneTemporary

Size
6 KB
Referenced Files
None
Subscribers
None

D218.1749463259.diff

diff --git a/src/matrix-link.hpp b/src/matrix-link.hpp
--- a/src/matrix-link.hpp
+++ b/src/matrix-link.hpp
@@ -43,8 +43,10 @@
bool isEvent() const;
QStringList identifiers() const;
QStringList routingServers() const;
+ QString action() const;
private:
std::vector<std::pair<Type, QString>> m_identifiers;
QStringList m_routingServers;
+ QString m_action;
};
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,32 @@
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};
+ }
+}
+
+QString parseMatrixSchemeAction(QString query)
+{
+ auto q = QUrlQuery{query};
+ auto actions = q.allQueryItemValues(u"action"_s);
+ if (actions.isEmpty()) {
+ return u""_s;
+ } else {
+ return actions.last();
+ }
+}
+
MatrixLink::MatrixLink(const QUrl &url)
{
// matrix.to link
@@ -57,6 +83,21 @@
}
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);
+ m_action = parseMatrixSchemeAction(query);
}
}
@@ -101,3 +142,8 @@
{
return m_routingServers;
}
+
+QString MatrixLink::action() const
+{
+ return m_action;
+}
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
@@ -23,6 +23,7 @@
void testRoomLink();
void testEventLink();
void testRoutingServers();
+ void testAction();
};
void MatrixLinkTest::testInvalidLink()
@@ -35,6 +36,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 +56,8 @@
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),
+ QUrl(u"matrix:u/alice%3Aexample.org"_s),
};
for (auto link : links) {
MatrixLink ml(link);
@@ -68,6 +77,10 @@
{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:r/somewhere%3Aexample.org"_s}, u"#somewhere:example.org"_s},
+ {QUrl(u"matrix:roomid/somewhere:example.org"_s), u"!somewhere:example.org"_s},
+ {QUrl(u"matrix:roomid/somewhere%3Aexample.org"_s), u"!somewhere:example.org"_s},
};
for (auto [link, pointed] : links) {
MatrixLink ml(link);
@@ -83,6 +96,10 @@
{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:r/somewhere%3Aexample.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},
+ {QUrl(u"matrix:roomid/somewhere%3Aexample.org/e/event:example.org"_s), u"!somewhere:example.org"_s},
};
for (auto [link, pointed] : links) {
MatrixLink ml(link);
@@ -100,6 +117,20 @@
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}));
+}
+
+void MatrixLinkTest::testAction()
+{
+ QCOMPARE(MatrixLink(QUrl(u"matrix:u/alice:example.org?action=chat"_s)).action(), u"chat"_s);
+ QCOMPARE(MatrixLink(QUrl(u"matrix:r/somewhere:example.org?action=join&via=a.org"_s)).action(), u"join");
}
QTEST_MAIN(MatrixLinkTest)

File Metadata

Mime Type
text/plain
Expires
Mon, Jun 9, 3:00 AM (17 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
213195
Default Alt Text
D218.1749463259.diff (6 KB)

Event Timeline