aboutsummaryrefslogtreecommitdiff
path: root/lib/uri.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-02-21 20:20:38 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-02-21 20:20:38 +0100
commit86f24d1ecf300b82b3a7253b81a2c392669d2c2b (patch)
treef733ffab1e5e54a63978a5b8cedf5cd032e2747e /lib/uri.cpp
parent221cc9faf713eb383a0e76a56018794796690369 (diff)
downloadlibquotient-86f24d1ecf300b82b3a7253b81a2c392669d2c2b.tar.gz
libquotient-86f24d1ecf300b82b3a7253b81a2c392669d2c2b.zip
Uri: support abbreviated types in Matrix URIs
As per the latest iteration of MSC2312, room/, user/ and event/ are only supported for parsing and replication but not for emitting from Matrix identifiers.
Diffstat (limited to 'lib/uri.cpp')
-rw-r--r--lib/uri.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/uri.cpp b/lib/uri.cpp
index e0912eb6..9eefdc83 100644
--- a/lib/uri.cpp
+++ b/lib/uri.cpp
@@ -7,13 +7,19 @@
using namespace Quotient;
struct ReplacePair { QByteArray uriString; char sigil; };
-/// Defines bi-directional mapping of path prefixes and sigils
+/// \brief Defines bi-directional mapping of path prefixes and sigils
+///
+/// When there are two prefixes for the same sigil, the first matching
+/// entry for a given sigil is used.
static const auto replacePairs = {
- ReplacePair { "user/", '@' },
+ ReplacePair { "u/", '@' },
+ { "user/", '@' },
{ "roomid/", '!' },
+ { "r/", '#' },
{ "room/", '#' },
// The notation for bare event ids is not proposed in MSC2312 but there's
// https://github.com/matrix-org/matrix-doc/pull/2644
+ { "e/", '$' },
{ "event/", '$' }
};
@@ -94,7 +100,7 @@ Uri::Uri(QUrl url) : QUrl(std::move(url))
case 2:
break;
case 4:
- if (splitPath[2] == "event")
+ if (splitPath[2] == "event" || splitPath[2] == "e")
break;
[[fallthrough]];
default:
@@ -147,7 +153,8 @@ Uri::Type Uri::type() const { return primaryType_; }
Uri::SecondaryType Uri::secondaryType() const
{
- return pathSegment(*this, 2) == "event" ? EventId : NoSecondaryId;
+ const auto& type2 = pathSegment(*this, 2);
+ return type2 == "event" || type2 == "e" ? EventId : NoSecondaryId;
}
QUrl Uri::toUrl(UriForm form) const