Skip to content

Commit

Permalink
Merge #798(kitsune): Fixes and cleanup again
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Sep 13, 2024
2 parents b464727 + 7c0ef43 commit b883c61
Show file tree
Hide file tree
Showing 38 changed files with 123 additions and 133 deletions.
35 changes: 16 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,22 @@ to make the review easier.

### C++ feature set

As of Quotient 0.8, the C++ standard for newly written code is C++20. Since none
of the supported compilers (GCC 11, Clang 11, Apple Clang 12, MSVC 19.30 - see
also the pre-requisites in [README](./README.md)) can handle the entire C++20
feature set, we have to stick with a subset. Most notably:

- `std::bind_front`, ranges, `std::format`, `std::source_location` can't be used
yet;
- while concepts and constraints as a language feature are there, most library
concepts are not available as of Apple Clang 12;
- No `constexpr` containers except `std::array` (but you can, and should,
use `QLatin1String` and `Quotient::operator""_ls` that creates it, for
constexpr Latin-1 strings).

The [compiler support page](https://en.cppreference.com/w/cpp/compiler_support#cpp20),
of cppreference.com, combined with the list of compiler versions above, can be
used to check whether a given feature is there. Be mindful that Clang build
configuration on Linux does not use Clang libc++ but rather the GNU standard
library (i.e. you should look at Clang column for core language features but
GCC libstdc++ for library features).
As of Quotient 0.9, the C++ standard for newly written code is C++20, save for a few exceptions
that the currently supported toolchains still don't have, most notably:
- template parameteres for type aliases and aggregates still cannot be deduced yet, you have
to explicitly specify those;
- modules support, while formally there, is missing standard library header units; sticking with
good old `#include`s in this cycle.

You can also try to use some C++23 library features; libQuotient is compiled with C++23 flags. The
[compiler support page at cppreference](https://en.cppreference.com/w/cpp/compiler_support#cpp23)
is a nice tool to check whether you can try using a specific language or library feature; refer
to the list of toolchain versions in [README](./README.md) for the compatibility baseline.
Be mindful that Clang build configuration on Linux does not use LLVM project's libc++ but rather
the GNU C++ standard library (i.e. you should look at Clang column for core language features
but GCC libstdc++ for library features). Most of the limitations, however, are due to Apple's
standard library - they have their own spin of libc++ that is constantly behind vanilla and, as
of now, the poorest in terms of features.

### Code style and formatting

Expand Down
4 changes: 2 additions & 2 deletions Quotient/csapi/administrative_contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Delete3pidFromAccountJob::Delete3pidFromAccountJob(const QString& medium, const
addParam<>(_dataJson, "medium"_L1, medium);
addParam<>(_dataJson, "address"_L1, address);
setRequestData({ _dataJson });
addExpectedKey("id_server_unbind_result");
addExpectedKey(u"id_server_unbind_result"_s);
}

Unbind3pidFromAccountJob::Unbind3pidFromAccountJob(const QString& medium, const QString& address,
Expand All @@ -68,7 +68,7 @@ Unbind3pidFromAccountJob::Unbind3pidFromAccountJob(const QString& medium, const
addParam<>(_dataJson, "medium"_L1, medium);
addParam<>(_dataJson, "address"_L1, address);
setRequestData({ _dataJson });
addExpectedKey("id_server_unbind_result");
addExpectedKey(u"id_server_unbind_result"_s);
}

RequestTokenTo3PIDEmailJob::RequestTokenTo3PIDEmailJob(const EmailValidationData& data)
Expand Down
2 changes: 1 addition & 1 deletion Quotient/csapi/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ GetCapabilitiesJob::GetCapabilitiesJob()
: BaseJob(HttpVerb::Get, u"GetCapabilitiesJob"_s,
makePath("/_matrix/client/v3", "/capabilities"))
{
addExpectedKey("capabilities");
addExpectedKey(u"capabilities"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/content-repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ UploadContentJob::UploadContentJob(QIODevice* content, const QString& filename,
{
setRequestHeader("Content-Type", contentType.toLatin1());
setRequestData({ content });
addExpectedKey("content_uri");
addExpectedKey(u"content_uri"_s);
}

auto queryToUploadContentToMXC(const QString& filename)
Expand Down Expand Up @@ -47,7 +47,7 @@ QUrl CreateContentJob::makeRequestUrl(const HomeserverData& hsData)
CreateContentJob::CreateContentJob()
: BaseJob(HttpVerb::Post, u"CreateContentJob"_s, makePath("/_matrix", "/media/v1/create"))
{
addExpectedKey("content_uri");
addExpectedKey(u"content_uri"_s);
}

auto queryToGetContent(bool allowRemote, qint64 timeoutMs, bool allowRedirect)
Expand Down
2 changes: 1 addition & 1 deletion Quotient/csapi/create_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CreateRoomJob::CreateRoomJob(const QString& visibility, const QString& roomAlias
addParam<IfNotEmpty>(_dataJson, "is_direct"_L1, isDirect);
addParam<IfNotEmpty>(_dataJson, "power_level_content_override"_L1, powerLevelContentOverride);
setRequestData({ _dataJson });
addExpectedKey("room_id");
addExpectedKey(u"room_id"_s);
}
2 changes: 1 addition & 1 deletion Quotient/csapi/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ GetLocalAliasesJob::GetLocalAliasesJob(const QString& roomId)
: BaseJob(HttpVerb::Get, u"GetLocalAliasesJob"_s,
makePath("/_matrix/client/v3", "/rooms/", roomId, "/aliases"))
{
addExpectedKey("aliases");
addExpectedKey(u"aliases"_s);
}
2 changes: 1 addition & 1 deletion Quotient/csapi/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DefineFilterJob::DefineFilterJob(const QString& userId, const Filter& filter)
makePath("/_matrix/client/v3", "/user/", userId, "/filter"))
{
setRequestData({ toJson(filter) });
addExpectedKey("filter_id");
addExpectedKey(u"filter_id"_s);
}

QUrl GetFilterJob::makeRequestUrl(const HomeserverData& hsData, const QString& userId,
Expand Down
4 changes: 2 additions & 2 deletions Quotient/csapi/joining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JoinRoomByIdJob::JoinRoomByIdJob(const QString& roomId,
addParam<IfNotEmpty>(_dataJson, "third_party_signed"_L1, thirdPartySigned);
addParam<IfNotEmpty>(_dataJson, "reason"_L1, reason);
setRequestData({ _dataJson });
addExpectedKey("room_id");
addExpectedKey(u"room_id"_s);
}

auto queryToJoinRoom(const QStringList& serverName)
Expand All @@ -34,5 +34,5 @@ JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const QStringList& server
addParam<IfNotEmpty>(_dataJson, "third_party_signed"_L1, thirdPartySigned);
addParam<IfNotEmpty>(_dataJson, "reason"_L1, reason);
setRequestData({ _dataJson });
addExpectedKey("room_id");
addExpectedKey(u"room_id"_s);
}
48 changes: 24 additions & 24 deletions Quotient/csapi/key_backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PostRoomKeysVersionJob::PostRoomKeysVersionJob(const QString& algorithm, const Q
addParam<>(_dataJson, "algorithm"_L1, algorithm);
addParam<>(_dataJson, "auth_data"_L1, authData);
setRequestData({ _dataJson });
addExpectedKey("version");
addExpectedKey(u"version"_s);
}

QUrl GetRoomKeysVersionCurrentJob::makeRequestUrl(const HomeserverData& hsData)
Expand All @@ -24,11 +24,11 @@ GetRoomKeysVersionCurrentJob::GetRoomKeysVersionCurrentJob()
: BaseJob(HttpVerb::Get, u"GetRoomKeysVersionCurrentJob"_s,
makePath("/_matrix/client/v3", "/room_keys/version"))
{
addExpectedKey("algorithm");
addExpectedKey("auth_data");
addExpectedKey("count");
addExpectedKey("etag");
addExpectedKey("version");
addExpectedKey(u"algorithm"_s);
addExpectedKey(u"auth_data"_s);
addExpectedKey(u"count"_s);
addExpectedKey(u"etag"_s);
addExpectedKey(u"version"_s);
}

QUrl GetRoomKeysVersionJob::makeRequestUrl(const HomeserverData& hsData, const QString& version)
Expand All @@ -41,11 +41,11 @@ GetRoomKeysVersionJob::GetRoomKeysVersionJob(const QString& version)
: BaseJob(HttpVerb::Get, u"GetRoomKeysVersionJob"_s,
makePath("/_matrix/client/v3", "/room_keys/version/", version))
{
addExpectedKey("algorithm");
addExpectedKey("auth_data");
addExpectedKey("count");
addExpectedKey("etag");
addExpectedKey("version");
addExpectedKey(u"algorithm"_s);
addExpectedKey(u"auth_data"_s);
addExpectedKey(u"count"_s);
addExpectedKey(u"etag"_s);
addExpectedKey(u"version"_s);
}

PutRoomKeysVersionJob::PutRoomKeysVersionJob(const QString& version, const QString& algorithm,
Expand Down Expand Up @@ -84,8 +84,8 @@ PutRoomKeyBySessionIdJob::PutRoomKeyBySessionIdJob(const QString& roomId, const
queryToPutRoomKeyBySessionId(version))
{
setRequestData({ toJson(data) });
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}

auto queryToGetRoomKeyBySessionId(const QString& version)
Expand Down Expand Up @@ -134,8 +134,8 @@ DeleteRoomKeyBySessionIdJob::DeleteRoomKeyBySessionIdJob(const QString& roomId,
makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", sessionId),
queryToDeleteRoomKeyBySessionId(version))
{
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}

auto queryToPutRoomKeysByRoomId(const QString& version)
Expand All @@ -152,8 +152,8 @@ PutRoomKeysByRoomIdJob::PutRoomKeysByRoomIdJob(const QString& roomId, const QStr
queryToPutRoomKeysByRoomId(version))
{
setRequestData({ toJson(backupData) });
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}

auto queryToGetRoomKeysByRoomId(const QString& version)
Expand Down Expand Up @@ -197,8 +197,8 @@ DeleteRoomKeysByRoomIdJob::DeleteRoomKeysByRoomIdJob(const QString& roomId, cons
makePath("/_matrix/client/v3", "/room_keys/keys/", roomId),
queryToDeleteRoomKeysByRoomId(version))
{
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}

auto queryToPutRoomKeys(const QString& version)
Expand All @@ -215,8 +215,8 @@ PutRoomKeysJob::PutRoomKeysJob(const QString& version, const QHash<RoomId, RoomK
QJsonObject _dataJson;
addParam<>(_dataJson, "rooms"_L1, rooms);
setRequestData({ _dataJson });
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}

auto queryToGetRoomKeys(const QString& version)
Expand All @@ -236,7 +236,7 @@ GetRoomKeysJob::GetRoomKeysJob(const QString& version)
: BaseJob(HttpVerb::Get, u"GetRoomKeysJob"_s, makePath("/_matrix/client/v3", "/room_keys/keys"),
queryToGetRoomKeys(version))
{
addExpectedKey("rooms");
addExpectedKey(u"rooms"_s);
}

auto queryToDeleteRoomKeys(const QString& version)
Expand All @@ -256,6 +256,6 @@ DeleteRoomKeysJob::DeleteRoomKeysJob(const QString& version)
: BaseJob(HttpVerb::Delete, u"DeleteRoomKeysJob"_s,
makePath("/_matrix/client/v3", "/room_keys/keys"), queryToDeleteRoomKeys(version))
{
addExpectedKey("etag");
addExpectedKey("count");
addExpectedKey(u"etag"_s);
addExpectedKey(u"count"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ UploadKeysJob::UploadKeysJob(const std::optional<DeviceKeys>& deviceKeys,
addParam<IfNotEmpty>(_dataJson, "one_time_keys"_L1, oneTimeKeys);
addParam<IfNotEmpty>(_dataJson, "fallback_keys"_L1, fallbackKeys);
setRequestData({ _dataJson });
addExpectedKey("one_time_key_counts");
addExpectedKey(u"one_time_key_counts"_s);
}

QueryKeysJob::QueryKeysJob(const QHash<UserId, QStringList>& deviceKeys, std::optional<int> timeout)
Expand All @@ -33,7 +33,7 @@ ClaimKeysJob::ClaimKeysJob(const QHash<UserId, QHash<QString, QString>>& oneTime
addParam<IfNotEmpty>(_dataJson, "timeout"_L1, timeout);
addParam<>(_dataJson, "one_time_keys"_L1, oneTimeKeys);
setRequestData({ _dataJson });
addExpectedKey("one_time_keys");
addExpectedKey(u"one_time_keys"_s);
}

auto queryToGetKeysChanges(const QString& from, const QString& to)
Expand Down
2 changes: 1 addition & 1 deletion Quotient/csapi/knocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ KnockRoomJob::KnockRoomJob(const QString& roomIdOrAlias, const QStringList& serv
QJsonObject _dataJson;
addParam<IfNotEmpty>(_dataJson, "reason"_L1, reason);
setRequestData({ _dataJson });
addExpectedKey("room_id");
addExpectedKey(u"room_id"_s);
}
2 changes: 1 addition & 1 deletion Quotient/csapi/list_joined_rooms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ QUrl GetJoinedRoomsJob::makeRequestUrl(const HomeserverData& hsData)
GetJoinedRoomsJob::GetJoinedRoomsJob()
: BaseJob(HttpVerb::Get, u"GetJoinedRoomsJob"_s, makePath("/_matrix/client/v3", "/joined_rooms"))
{
addExpectedKey("joined_rooms");
addExpectedKey(u"joined_rooms"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/list_public_rooms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GetPublicRoomsJob::GetPublicRoomsJob(std::optional<int> limit, const QString& si
: BaseJob(HttpVerb::Get, u"GetPublicRoomsJob"_s, makePath("/_matrix/client/v3", "/publicRooms"),
queryToGetPublicRooms(limit, since, server), {}, false)
{
addExpectedKey("chunk");
addExpectedKey(u"chunk"_s);
}

auto queryToQueryPublicRooms(const QString& server)
Expand All @@ -71,5 +71,5 @@ QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, std::optional<in
addParam<IfNotEmpty>(_dataJson, "include_all_networks"_L1, includeAllNetworks);
addParam<IfNotEmpty>(_dataJson, "third_party_instance_id"_L1, thirdPartyInstanceId);
setRequestData({ _dataJson });
addExpectedKey("chunk");
addExpectedKey(u"chunk"_s);
}
6 changes: 3 additions & 3 deletions Quotient/csapi/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LoginJob::LoginJob(const QString& type, const std::optional<UserIdentifier>& ide
addParam<IfNotEmpty>(_dataJson, "initial_device_display_name"_L1, initialDeviceDisplayName);
addParam<IfNotEmpty>(_dataJson, "refresh_token"_L1, refreshToken);
setRequestData({ _dataJson });
addExpectedKey("user_id");
addExpectedKey("access_token");
addExpectedKey("device_id");
addExpectedKey(u"user_id"_s);
addExpectedKey(u"access_token"_s);
addExpectedKey(u"device_id"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/login_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ GenerateLoginTokenJob::GenerateLoginTokenJob(const std::optional<AuthenticationD
QJsonObject _dataJson;
addParam<IfNotEmpty>(_dataJson, "auth"_L1, auth);
setRequestData({ _dataJson });
addExpectedKey("login_token");
addExpectedKey("expires_in_ms");
addExpectedKey(u"login_token"_s);
addExpectedKey(u"expires_in_ms"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/message_pagination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ GetRoomEventsJob::GetRoomEventsJob(const QString& roomId, const QString& dir, co
makePath("/_matrix/client/v3", "/rooms/", roomId, "/messages"),
queryToGetRoomEvents(from, to, dir, limit, filter))
{
addExpectedKey("start");
addExpectedKey("chunk");
addExpectedKey(u"start"_s);
addExpectedKey(u"chunk"_s);
}
2 changes: 1 addition & 1 deletion Quotient/csapi/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ GetNotificationsJob::GetNotificationsJob(const QString& from, std::optional<int>
makePath("/_matrix/client/v3", "/notifications"),
queryToGetNotifications(from, limit, only))
{
addExpectedKey("notifications");
addExpectedKey(u"notifications"_s);
}
2 changes: 1 addition & 1 deletion Quotient/csapi/presence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ GetPresenceJob::GetPresenceJob(const QString& userId)
: BaseJob(HttpVerb::Get, u"GetPresenceJob"_s,
makePath("/_matrix/client/v3", "/presence/", userId, "/status"))
{
addExpectedKey("presence");
addExpectedKey(u"presence"_s);
}
6 changes: 3 additions & 3 deletions Quotient/csapi/pushrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QUrl GetPushRulesJob::makeRequestUrl(const HomeserverData& hsData)
GetPushRulesJob::GetPushRulesJob()
: BaseJob(HttpVerb::Get, u"GetPushRulesJob"_s, makePath("/_matrix/client/v3", "/pushrules"))
{
addExpectedKey("global");
addExpectedKey(u"global"_s);
}

QUrl GetPushRuleJob::makeRequestUrl(const HomeserverData& hsData, const QString& scope,
Expand Down Expand Up @@ -76,7 +76,7 @@ IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope, const QString&
makePath("/_matrix/client/v3", "/pushrules/", scope, "/", kind, "/", ruleId,
"/enabled"))
{
addExpectedKey("enabled");
addExpectedKey(u"enabled"_s);
}

SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString& kind,
Expand All @@ -103,7 +103,7 @@ GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope, const QString
makePath("/_matrix/client/v3", "/pushrules/", scope, "/", kind, "/", ruleId,
"/actions"))
{
addExpectedKey("actions");
addExpectedKey(u"actions"_s);
}

SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString& kind,
Expand Down
2 changes: 1 addition & 1 deletion Quotient/csapi/refresh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ RefreshJob::RefreshJob(const QString& refreshToken)
QJsonObject _dataJson;
addParam<>(_dataJson, "refresh_token"_L1, refreshToken);
setRequestData({ _dataJson });
addExpectedKey("access_token");
addExpectedKey(u"access_token"_s);
}
4 changes: 2 additions & 2 deletions Quotient/csapi/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RegisterJob::RegisterJob(const QString& kind, const std::optional<Authentication
addParam<IfNotEmpty>(_dataJson, "inhibit_login"_L1, inhibitLogin);
addParam<IfNotEmpty>(_dataJson, "refresh_token"_L1, refreshToken);
setRequestData({ _dataJson });
addExpectedKey("user_id");
addExpectedKey(u"user_id"_s);
}

RequestTokenToRegisterEmailJob::RequestTokenToRegisterEmailJob(const EmailValidationData& data)
Expand Down Expand Up @@ -82,7 +82,7 @@ DeactivateAccountJob::DeactivateAccountJob(const std::optional<AuthenticationDat
addParam<IfNotEmpty>(_dataJson, "id_server"_L1, idServer);
addParam<IfNotEmpty>(_dataJson, "erase"_L1, erase);
setRequestData({ _dataJson });
addExpectedKey("id_server_unbind_result");
addExpectedKey(u"id_server_unbind_result"_s);
}

auto queryToCheckUsernameAvailability(const QString& username)
Expand Down
2 changes: 1 addition & 1 deletion Quotient/csapi/registration_tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ RegistrationTokenValidityJob::RegistrationTokenValidityJob(const QString& token)
makePath("/_matrix/client/v1", "/register/m.login.registration_token/validity"),
queryToRegistrationTokenValidity(token), {}, false)
{
addExpectedKey("valid");
addExpectedKey(u"valid"_s);
}
Loading

0 comments on commit b883c61

Please sign in to comment.