aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2022-07-12Make AliasesEventContent a simple structureAlexey Rusakov
JSON conversions are moved out of the class, obviating the need to define the plain data constructor and gaining default-constructibility along the way - previously the default constructor was preempted by user-defined ones.
2022-07-12Refactor things around EncryptionEvent[Content]Alexey Rusakov
EncryptionEvent was marked as Q_GADGET only for the sake of defining EncryptionType inside of it as Q_ENUM, with aliases also available under Quotient:: and EncryptionEventContent. This is a legacy from pre-Q_ENUM_NS times. However, event types are not really made to be proper Q_GADGETs: Q_GADGET implies access by value or reference but event types are uncopyable for the former and QML is ill-equipped for the latter. This commit moves EncryptionType definition to where other such enumerations reside - on the namespace level in quotient_common.h; and the other two places are now deprecated; and EncryptionEvent is no more Q_GADGET. With fromJson/toJson refactored in the previous commit there's no more need to specialise JsonConverter<>: specialising fromJson() is just enough. Moving EncryptionType to quotient_common.h exposed the clash of two Undefined enumerators (in RoomType and EncryptionType), warranting both enumerations to become scoped (which they ought to be, anyway). And while we're at it, the base type of enumerations is specified explicitly, as MSVC apparently uses a signed base type (int?) by default, unlike other compilers, and the upcoming enum converters will assume an unsigned base type. Finally, using fillFromJson() instead of fromJson() in the EncryptionEventContent constructor allowed to make default values explicit in the header file, rather than buried in the initialisation code.
2022-07-12fromJson()/toJson() refactoringAlexey Rusakov
fromJson() is generalised to accept any JSON-like type while passing QJsonObject to JsonConverter<>::load (instead of doLoad). This allows to (still) rely on JsonConverter<> as a customisation point while providing an opportunity to overload fromJson for custom types in a pointed way (specifically, by providing the overload for `fromJson(const QJsonObject&)`), instead of having to go with full-blown JsonConverter<> specialisation. This will be used in a further commit to simplify ReceiptEvent definition. Using if constexpr in combination with constraints (`requires()`) - the first such case in Quotient codebase - allowed to put the entire logic in a single JsonConverter<>::load() body instead of having a facility JsonExporter<> class for SFINAE. Aside from that, fromJson<QJsonValue, QJsonValue> is entirely dropped because it's not supposed to be used that way (it's no-op after all); reflecting that, Event::unsignedPart() and Event::contentPart() no more default to QJsonValue as the expected return type, you have to explicitly provide the type instead (and as one can see from the changes in the commit, it's actually better that way since it's better to validate the value inside JSON - e.g. check QString or QJsonObject for emptiness - than the QJsonValue envelope which may still wrap an empty value). toJson() is also generalised, replacing 3 functions with one that has a constexpr if to discern between two kinds of types.
2022-07-12Fix deprecation messagesAlexey Rusakov
[skip ci]
2022-07-12Pack up StickerEvent in the header fileAlexey Rusakov
Dropping yet another translation unit.
2022-07-11Reuse Room::setState() overloads from one anotherAlexey Rusakov
2022-07-11Add QUOTIENT_API to RoomStateViewAlexey Rusakov
Fixing link errors at non-template RoomStateView::get() when building with libQuotient as a shared object. There's also a test in quotest.cpp now to cover that case.
2022-07-08qt_connection_util.h: use autoAlexey Rusakov
2022-07-08CI: use GCC 11 and (therefore) ubuntu-22.04Alexey Rusakov
GCC 10 ICE's[1] in qt_connection_util.h code; and ubuntu-20.04 doesn't have GCC 11. Also: patch a Qt 5.15 header when compiling with GCC because a combination of Qt 5.15 and GCC 11 in turn triggers QTBUG-91909/90568... Which in turn required moving Qt setup before the build environment setup. Life's fun. [1] Internal Compiler Error
2022-07-07Avoid std::derived_from and std::bind_frontAlexey Rusakov
Apple Clang doesn't have those yet.
2022-07-03Shorten switchOnType, function_traits and connect*Alexey Rusakov
...thanks to C++20 awesomeness. A notable change is that wrap_in_function() (and respectively function_traits<>::function_type) and fn_return_t alias are gone. The former are no more needed because connectUntil/connectSingleShot no more use std::function. The latter has been relatively underused and with the optimisation of switchOnType hereby, could be completely replaced with std::invoke_result_t. Rewriting connect* functions using constexpr and auto parameters made the implementation 30% more compact and much easier to understand (though still with a couple of - now thoroughly commented - tricky places). Dropping std::function<> from it may also bring some (quite modest, likely) performance benefits.
2022-06-24Make EventContent::Base() move constructor noexceptAlexey Rusakov
2022-06-24Fix the just introduced Sonar warningAlexey Rusakov
Too many parameters of the same type in a row.
2022-06-24Start using C++20's designated initializersAlexey Rusakov
2022-06-24Code cleanup and reformattingAlexey Rusakov
2022-06-24Rework SignedOneTimeKey as a QJsonObject wrapperAlexey Rusakov
Since this object has to be verified against a signature it also carries there's a rather specific procedure described in The Spec for that. That procedure basically assumes handling the signed one-time key object as a JSON object, not as a C++ object. And originally Quotient E2EE code was exactly like that (obtaining the right QJsonObject from the job result and handling it as specced) but then one enthusiastic developer (me) decided it's better to use a proper C++ structure - breaking the verification logic along the way. After a couple attempts to fix it, here we are again: SignedOneTimeKey is a proper QJsonObject, and even provides a method returning its JSON in the form prepared for verification (according to the spec).
2022-06-24Fix copy-pasta in signed one-time key JSON dumperAlexey Rusakov
2022-06-23Streamline Room::P::shouldRotateMegolmSession()Alexey Rusakov
Now there's only 1 instead of 5 lookups of the same EncryptionEvent, and the code is shorter.
2022-06-23Use QUO_CONTENT_GETTERAlexey Rusakov
In keyverificationevent.*, this massively shortens repetitive getter definitions; the remaining few non-trivial ones are moved to keyverificationevent.h, dropping the respective .cpp file and therefore the dedicated translation unit. In roomkeyevent.h, it's just shorter.
2022-06-23Drop QUOTIENT_API where it's undueAlexey Rusakov
2022-06-22Fix signature verificationAlexey Rusakov
toJson(SignedOneTimeKey) incorrectly generated a "signatures" key mapped to an empty object when no signatures were in the C++ value. Also: fallback keys have an additional flag that also has to be taken into account when verifying signatures.
2022-06-22RoomSummary::merge(): explicitly cast between int and boolAlexey Rusakov
Honestly, it was quite intuitive even without that, but in reality there are implicit conversion under the wraps. This commit makes them explicit, for clarity.
2022-06-22Streamline RoomPowerLevelsEvent backoffice codeAlexey Rusakov
Also: leave a link at the place in the spec with power level defaults to make it clear they are not invented out of thin air.
2022-06-22Address a few more Sonar warningsAlexey Rusakov
2022-06-22Clean up RequestData from Sonar warningsAlexey Rusakov
Also: make ImplPtr more flexible.
2022-06-22Use fixed width types for enumsAlexey Rusakov
2022-06-21Fix a few clang-tidy/GCC warningsAlexey Rusakov
2022-06-21Move out Overloads to util.hAlexey Rusakov
...instead of tucking the template in filesourceinfo.cpp where it surely will be forgotten.
2022-06-21room.cpp: replace two signal connections with oneAlexey Rusakov
2022-06-19Add a missing #includeAlexey Rusakov
2022-06-18Move C++-only macros to util.hAlexey Rusakov
This pertains to QUO_IMPLICIT and DECL_DEPRECATED_ENUMERATOR - both can be used with no connection to Qt meta-type system (which is what quotient_common.h is for).
2022-06-18Drop make_array(); use std::to_array() where neededAlexey Rusakov
make_array() has been introduced to cover for shortcomings on macOS and Windows. These shortcomings are no more there, so we can just use the standardrlibrary.
2022-06-18Drop pre-Qt 5.15 codeAlexey Rusakov
2022-06-18Regenerate API files upon the previous commitAlexey Rusakov
2022-06-17Further fix building with Qt 6Alexey Rusakov
Also: build with Qt 6 first, so that it fails sooner.
2022-06-17Make Connection::sendToDevices() an actual slotAlexey Rusakov
Although Qt 5 didn't complain about that, you could never really use sendToDevices() in its slot (or even invocable) capacity because Qt's meta-type system could not handle move-only UsersToDevicesToEvents. Qt 6 is more stringent; the build fails at trying to instantiate QMetaType for that type (with a rather unhelpful error message thrown by Clang, and more helpful but very verbose diagnostic from MSVC) because it does not provide a copy constructor. However, sendToDevice doesn't really need to have full-blown events in that parameter; just the content of the event is equally fine. This commit does exactly that: replaces UsersToDevicesToEvents with UsersToDevicesToContent that contains QJsonObject's instead of EventPtr's. The code around is updated accordingly. Also: factor out the key event JSON creation from makeMessageEventForSessionKey() because it's the same JSON for each target device; the function therefore is called encryptSessionKeyEvent() now.
2022-06-11Regenerate API files using latest matrix-specAlexey Rusakov
New: - refresh tokens support (changes in login.* and registration.*; RefreshJob); - GetRelatingEvents[WithRelType[AndEventType]]Job Changed space_hierarchy.*: - childrenState is of type StateEvents now; limit and maxDepth are (omittable) integers, not doubles. - no more unused `stripped_state.h` file inclusion.
2022-06-11Regenerate API filesAlexey Rusakov
The latest GTAD no more emits public_rooms_chunk.h (public_rooms_response.h already has the same definition), and skips on PublicRoomsResponse structure that is never used.
2022-06-08Save connection state while QCoreApplication is still thereAlexey Rusakov
This reimplements #558 in a more reliable way. Deconstruction of AccountRegistry may (or may not, yay for static initialisation) occur after deconstruction of QCoreApplication, in which case an attempt to determine the directory for the state fails because it depends on the application object existence.
2022-06-06Regenerate API filesAlexey Rusakov
This only updates 3 files affected by the change in the previous commit.
2022-06-04Address Sonar warningsAlexey Rusakov
2022-06-02Merge pull request #560 from TobiasFella/createnewsessionwhenuserleavesAlexey Rusakov
2022-06-01Immediately create a new megolm session when user leaves instead ofTobias Fella
deferring until sending event
2022-06-01Merge pull request #559 from TobiasFella/removeaccountsloadingAlexey Rusakov
2022-06-01#554: Fix update-api jobsAlexey Rusakov
2022-06-01Fix FTBFS after the mergeAlexey Rusakov
2022-05-31Remove accounts from accountsLoading when they're no longer loadingTobias Fella
2022-05-31Merge branch 'dev' into update-api-updateAlexey Rusakov
2022-05-31Fix Room::getPreviousContent() to match new CS APIAlexey Rusakov
There was a fairly nasty change where `from` parameter in /messages became optional and that led to two QString parameters (`from` and `dir) switching positions. Because they have the same type, the problem only shows at runtime. This commit fixes Room::getPreviousContent() to pass the parameters at right positions; client code won't feel anything (unless it uses GetRoomEventsJob directly).
2022-05-31Tweak QOlmAccount and data structures aroundAlexey Rusakov
This is mainly to plug the definition of a string-to-variant map for one-time keys (see https://spec.matrix.org/v1.2/client-server-api/#key-algorithms) into the CS API generated code (see the "shortcut OneTimeKeys" commit for gtad.yaml); but along with it came considerable streamlining of code in qolmaccount.cpp. Using std::variant to store that map also warranted converters.h to gain support for that type (even wider than toJson() that is already in dev - a non-trivial merge from dev is in order).