From 7c0742aa2b0b548bf99abe43c1a0410a11576893 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 25 Jan 2021 21:33:40 +0100 Subject: Connection: stop login flows job before resolving This avoids a corner case when a login flows job finishes (or worse, goes for a retry) while the homeserver is (being) resolved, yielding the Connection object in an inconsistent state to the client. --- lib/connection.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/connection.cpp b/lib/connection.cpp index 3ed71bb4..0fb2d003 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -133,6 +133,11 @@ public: != "json"; bool lazyLoading = false; + /// \brief Stop resolving and login flows jobs, and clear login flows + /// + /// Prepares the class to set or resolve a new homeserver + void clearResolvingContext(); + /** \brief Check the homeserver and resolve it if needed, before connecting * * A single entry for functions that need to check whether the homeserver @@ -270,8 +275,7 @@ Connection::~Connection() void Connection::resolveServer(const QString& mxid) { - if (isJobRunning(d->resolverJob)) - d->resolverJob->abandon(); + d->clearResolvingContext(); auto maybeBaseUrl = QUrl::fromUserInput(serverPart(mxid)); maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http" @@ -1530,13 +1534,19 @@ QByteArray Connection::generateTxnId() const return d->data->generateTxnId(); } +void Connection::Private::clearResolvingContext() +{ + if (isJobRunning(resolverJob)) + resolverJob->abandon(); + if (isJobRunning(loginFlowsJob)) + loginFlowsJob->abandon(); + loginFlows.clear(); + +} + void Connection::setHomeserver(const QUrl& url) { - if (isJobRunning(d->resolverJob)) - d->resolverJob->abandon(); - if (isJobRunning(d->loginFlowsJob)) - d->loginFlowsJob->abandon(); - d->loginFlows.clear(); + d->clearResolvingContext(); if (homeserver() != url) { d->data->setBaseUrl(url); -- cgit v1.2.3 From b069c6bb377641840026aa37cb8acf7e2a76bfe5 Mon Sep 17 00:00:00 2001 From: Roland Pallai Date: Thu, 28 Jan 2021 14:58:11 +0100 Subject: Fix rich replies json format (transmit) With this patch it looks like: "m.relates_to": { "m.in_reply_to": { "event_id": "$another:event.com" } } instead of: "m.relates_to": { "event_id": "$another:event.com", "rel_type": "m.in_reply_to" }, So it fits the specification by now. https://matrix.org/docs/spec/client_server/r0.6.1#rich-replies (cherry picked from commit b850edadde2299b122a5cd17da85e943430e43b7) --- lib/events/roommessageevent.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index 616a034f..e2465e61 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -338,7 +338,10 @@ void TextContent::fillJson(QJsonObject* json) const } if (relatesTo) { json->insert(QStringLiteral("m.relates_to"), - QJsonObject { { "rel_type", relatesTo->type }, { EventIdKey, relatesTo->eventId } }); + relatesTo->type == RelatesTo::ReplyTypeId() ? + QJsonObject { { relatesTo->type, QJsonObject{ { EventIdKey, relatesTo->eventId } } } } : + QJsonObject { { "rel_type", relatesTo->type }, { EventIdKey, relatesTo->eventId } } + ); if (relatesTo->type == RelatesTo::ReplacementTypeId()) { QJsonObject newContentJson; if (mimeType.inherits("text/html")) { -- cgit v1.2.3 From 221cc9faf713eb383a0e76a56018794796690369 Mon Sep 17 00:00:00 2001 From: Roland Pallai Date: Thu, 28 Jan 2021 15:05:33 +0100 Subject: Fix rich edits (transmit) The new formatted_body was not included into new content on edit due to badly constructed json. (cherry picked from commit df6b2d31ec8f2f5890826719e960f450a4968f22) --- lib/events/roommessageevent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index e2465e61..e68e7d63 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -345,8 +345,8 @@ void TextContent::fillJson(QJsonObject* json) const if (relatesTo->type == RelatesTo::ReplacementTypeId()) { QJsonObject newContentJson; if (mimeType.inherits("text/html")) { - json->insert(FormatKey, HtmlContentTypeId); - json->insert(FormattedBodyKey, body); + newContentJson.insert(FormatKey, HtmlContentTypeId); + newContentJson.insert(FormattedBodyKey, body); } json->insert(QStringLiteral("m.new_content"), newContentJson); } -- cgit v1.2.3 From 86f24d1ecf300b82b3a7253b81a2c392669d2c2b Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 21 Feb 2021 20:20:38 +0100 Subject: 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. --- lib/uri.cpp | 15 +++++++++++---- tests/quotest.cpp | 4 ++++ 2 files changed, 15 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 diff --git a/tests/quotest.cpp b/tests/quotest.cpp index bcc5a119..6ad5e8a8 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -726,12 +726,15 @@ TEST_IMPL(visitResources) roomId, "matrix:roomid/" + roomId.mid(1), "https://matrix.to/#/%21"/*`!`*/ + roomId.mid(1), roomAlias, "matrix:room/" + roomAlias.mid(1), + "matrix:r/" + roomAlias.mid(1), "https://matrix.to/#/" + roomAlias, }; const QStringList userUris { userId, "matrix:user/" + userId.mid(1), + "matrix:u/" + userId.mid(1), "https://matrix.to/#/" + userId }; const QStringList eventUris { "matrix:room/" + roomAlias.mid(1) + "/event/" + eventId.mid(1), + "matrix:r/" + roomAlias.mid(1) + "/e/" + eventId.mid(1), "https://matrix.to/#/" + roomId + '/' + eventId }; // Check that reserved characters are correctly processed. @@ -745,6 +748,7 @@ TEST_IMPL(visitResources) static const QStringList joinByAliasUris { Uri(joinRoomAlias.toUtf8(), {}, joinQuery.mid(1)).toDisplayString(), "matrix:room/" + encodedRoomAliasNoSigil + joinQuery, + "matrix:r/" + encodedRoomAliasNoSigil + joinQuery, "https://matrix.to/#/%23"/*`#`*/ + encodedRoomAliasNoSigil + joinQuery, "https://matrix.to/#/%23" + joinRoomAlias.mid(1) /* unencoded */ + joinQuery }; -- cgit v1.2.3 From b25785d294669f2bab7dcd1e3cd1fba61991fe46 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 21 Feb 2021 20:47:36 +0100 Subject: Update a comment that still mentions Riot --- lib/events/roommessageevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index e68e7d63..de499e7c 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -313,7 +313,7 @@ TextContent::TextContent(const QJsonObject& json) const auto actualJson = isReplacement(relatesTo) ? json.value("m.new_content"_ls).toObject() : json; - // Special-casing the custom matrix.org's (actually, Riot's) way + // Special-casing the custom matrix.org's (actually, Element's) way // of sending HTML messages. if (actualJson["format"_ls].toString() == HtmlContentTypeId) { mimeType = HtmlMimeType; -- cgit v1.2.3 From ea9ff39ea147897e576a3a4664348ad77ceee501 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 21 Feb 2021 22:22:12 +0100 Subject: SECURITY.md: 0.5.x is no more supported It's been 2 years, time to move on. --- SECURITY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index e821aed1..3af71d18 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,6 @@ | ------- | ------------------ | | master | :white_check_mark: | | 0.6.x | :white_check_mark: | -| 0.5.x | :white_check_mark: | | older | :x: | ## Reporting a Vulnerability -- cgit v1.2.3 From 789433971a83a2d5ccad43e28402cd2bbbe0d640 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 21 Feb 2021 22:25:07 +0100 Subject: Update documentation Replace references to Spectral with NeoChat as a more lively and better supported client; deprecate qmake; remove a mention that libQuotient uses LGPL-2.1-only because it's not true, according to ./COPYING --- CONTRIBUTING.md | 3 +-- README.md | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 33c51033..1cf3eb6d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,8 +88,7 @@ a commit without a DCO is an accident and the DCO still applies. Unless a contributor explicitly specifies otherwise, we assume contributors to agree that all contributed code is released either under *LGPL v2.1 or later*. -This is more than just [LGPL v2.1 libQuotient now uses](./COPYING) -because the project plans to switch to LGPL v3 for library code in the near future. +The project plans to switch to LGPL v3 for library code in the near future.