aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2021-12-02Improve function_traits<>; split out from util.*Alexey Rusakov
Quotient::function_traits<> did not support member functions in a proper way (i.e. the way std::invoke_result<> treats them, with the function's owning class represented as the first parameter). Now that I gained the skill and understanding in function_traits<> somewhat wicked machinery, I could properly support member functions. Overloads and generic lambdas are not supported but maybe we'll get to those one day.
2021-12-02visit(Event, ...) -> switchOnType()Alexey Rusakov
It has not much to do with the Visitor design pattern; also, std::visit() has different conventions on the order of parameters.
2021-11-29Track room stubbed state size in logsAlexey Rusakov
2021-11-28Simplify converters.*Alexey Rusakov
There was a lot of excess redirection in fromJson() and toJson() with most of JsonConverter<> specialisations being unnecessary boilerplate. These have been replaced by overloads for toJson() and explicit specialisations for fromJson() wherever possible without breaking the conversion logic.
2021-11-28Comment on const return types in event.hAlexey Rusakov
Proper linters recognise that the returned types are not primitive, while people might still be confused a bit.
2021-11-28Don't std::move when the callee doesn't support itAlexey Rusakov
In both fixed cases the callee accepts a const reference, which makes std::move() useless. Static analyzers apparently missed them because the cases are inside a macro.
2021-11-28One more small thing to actually fix CI breakageAlexey Rusakov
It's might look weird; but without making fromJson() a specialisation it becomes an overload next to an implicit specialisation of the template function defined just above, and then loses to that specialisation because it (also) has the perfect match. (would be great if the compiler shaded the implicit specialisation in such cases - alas it's not how the standard works.)
2021-11-28Fix CI breakage caused by the previous commitAlexey Rusakov
2021-11-28Event::unsignedPart()Alexey Rusakov
Similar to contentPart() - apparently there are enough places across the code that would benefit from it.
2021-11-27basicEventJson(): dismiss with the templateAlexey Rusakov
Given that QJsonObject only accepts QStrings in the list constructor, the template is useless cruft.
2021-11-27Code cleanupAlexey Rusakov
2021-11-27Event::content() -> contentPart()Alexey Rusakov
There's a clash between Event::content() (a template function) and RoomMessageEvent::content() (plain member). Out of these two, the name more fits to the RME's member function - strictly speaking, Event::content() retrieves a part of content, and so is renamed. In addition, contentPart() defaults to QJsonValue now, which is pretty intuitive (the function returns values from a JSON object) and allows to implement more elaborate logic such as if (const auto v = contentPart<>("key"_ls); v.isObject()) { // foo } else if (v.isString()) { // bar } else { // boo }
2021-11-27Merge pull request #518 from Smittyvb/room-stateEventsAlexey Rusakov
2021-11-26Add Room::{stateEventsOfType,currentState}Smitty
This is useful for implementing Spaces support, where all events of type `m.space.child` are needed, and we don't know their state keys in advance.
2021-11-26Fix crashing on invalid member and encryption eventsAlexey Rusakov
The problem is in Room::processStateEvent(): after potentially-inserting-nullptr into currentState, pre-check failure (that may occur on member and trigger events for now) leaves that nullptr in the hash map. Basically anything that uses currentState (e.g., Room::toJson) assumes that currentState has no nullptrs - which leads to either an assertion failure, or nullptr dereferencing. The fix removes the nullptr placeholder if the pre-checks failed.
2021-11-26Room::processEphemeralEvents: Fix updatedCount always being zeroAlexey Rusakov
Trying to test bits with Changes::testFlag(Change::Any) was a bad idea. Along the way: made logging in setLastReadReceipt() refer to the actual timeline item when possible.
2021-11-26Revert "Drop #include "logging.h" from event.h"Alexey Rusakov
Doesn't really help build times, instead breaking the build on older Qt.
2021-11-26Event: deprecate originalJson[Object]()Alexey Rusakov
The "original JSON" wording is misleading: the returned JSON can be and is routinely edited as a part of event construction, redaction, editing. Also, originalJson() name is misleading in that it returns a stringified (in a very specific way) JSON and not an object. You have to call fullJson() to get the object, and originalJsonObject(), confusingly, returns exactly the same thing but as a value rather than as a reference. The original intention of keeping originalJsonObject() was to make it Q_INVOKABLE or use it as an accessor for a Q_PROPERTY. unfortunately, this was never really practical as discussed in the previous commit. All that implies that clients have to handle passing event JSON to QML themselves, in the form they prefer (as an object or a string). The added complexity is negligible though; on the other hand, there's added flexibility in, e.g., choosing a compact instead of default JSON layout or even generate a highlighted JSON representation.
2021-11-26Drop #include "logging.h" from event.hAlexey Rusakov
Makes compilation a tad lighter.
2021-11-26Drop Q_GADGET from most uncopyable classes; other minor cleanupAlexey Rusakov
Q_GADGET is generally used to enable two things outside of QObject: Q_PROPERTY/Q_INVOKABLE and Q_ENUM/Q_FLAG. While the latter can be used in its own right in QML, the former requires Q_GADGET instances to be passed to QML by value, which is not really possible with uncopyable/unassignable classes. Bottom line is that Q_PROPERTY in anything derived from Quotient::Event is not viable, making Q_GADGET macro useless unless there's a Q_ENUM/Q_FLAG (as is the case with RoomMessageEvent, e.g.).
2021-11-24Don't require C++20 from the clients just yetAlexey Rusakov
2021-11-22Fix stupid false-negatives from Room::updateStats()Alexey Rusakov
2021-11-22Fix a crash on trying to mark unknown events as fully readAlexey Rusakov
2021-11-21Log the hexadecimal value of Changes too, just in caseAlexey Rusakov
2021-11-21Document Room::Change and its enumeratorsAlexey Rusakov
2021-11-21EventStats and Room::partiallyRead/unreadStats()Alexey Rusakov
This introduces a new API to count unread events that would allow to obtain those unread and highlight counts since either the fully read marker (Room::partiallyReadStats) or the last read receipt (Room::unreadStats). Element uses the read receipt as the anchor to count unread numbers, while Quaternion historically used the fully read marker for that (with the pre-0.7 library sticking the two markers to each other). From now on the meaning of "unread" in Quotient is aligned with that of the spec and Element, and "partially read" means events between the fully read marker and the local read receipt; the design allows client authors to use either or both counting strategies as they see fit. Respectively, Room::P::setFullyReadMarker() updates partially-read statistics, while Room::P::setLastReadReceipt(), when called on a local user, updates unread statistics. Room::notificationCount() and Room::highlightCount() maintain their previous meaning as the counters since the last read receipt; Room::notificationCount() counts unread events locally, falling back to the value from the above-mentioned key defined by MSC2654, and if that is not there, further to `unread_notifications/notification_count` defined in the current spec. Room::highlightCount(), however, is still taken from the homeserver, not from Room::unreadStats().highlightCount.
2021-11-21Room::Private::postprocessChanges()Alexey Rusakov
This makes updating display name and emission of necessary signals including Room::changed() more systematic when it has to occur outside of updateData() flow - e.g. when loading all members.
2021-11-21SyncData: support MSC2654; partiallyReadCountAlexey Rusakov
Since MSC2654's unread count is counted from the m.read receipt, and the course is to follow the spec's terminology and use "unread count" for the number of notable events since m.read, this required to move the existing number of notable events since m.fully_read to another field, henceforth called partiallyReadCount. At the same time, SyncData::notificationCount is dropped completely since MSC2654 claims to supersede it. Also: Room::resetNotificationCount() and Room::resetHighlightCount() are deprecated, as these never worked properly overwriting values that can be calculated or sourced from the server, only for these values to be set back again the next time the room is updated from /sync.
2021-11-21Room: isEventNotable, notificationFor, checkForNotificationsAlexey Rusakov
Room::isEventNotable has been moved out from Room::Private and made compliant with MSC2654. The concept of Room::checkForNotifications is taken from Quaternion where a method with the same name has been in QuaternionRoom for a long time - however, actual body is a stub for now, always returning { Notification::None } (Quaternion's implementation is too crude to be taken to the library). Now we really need a pushrules processor to fill this method with something reasonably good. Internally the library now calls checkForNotifications() on every event added to the timeline, filling up the events-to-notifications map because it is anticipated that calculation of notifications can be rather resource-intensive and should only be done once for a given event. Finally, Room::notificationsFor is an accessor into the mentioned map, standing next to isEventNotable (but unlike isEventNotable, it's not virtual; checkForNotifications is).
2021-11-21Minor brushup in the comment to QUO_DECLARE_FLAGSAlexey Rusakov
[skip ci]
2021-11-19CleanupAlexey Rusakov
2021-11-19Make enum values logging more terse()Alexey Rusakov
By default enum class values are logged along with the qualifier; this may or may not be desirable in a given setting. For JoinState(s) and Membership(Mask) operator<< was overloaded to implicitly suppress qualification; however, this is both overly sweeping and uses Qt's internal API for the backend. Instead, a new QDebug manipulator, terse(), is introduced, that does the same as those operator<< overloads but on a per-invocation basis. This makes it slightly more verbose to log enums but makes the QDebug reconfiguration explicit and doesn't require to produce new overloads every time a new enum ends up in logs. And it's built entirely on the published Qt API, reusing the QDebugManip framework that Quotient already has. Also: operator<<(QDebug, QDebugManip) has been moved out of the namespace to fix lookup issues when there's no prior `using namespace Quotient`.
2021-11-18Make Room::Changes an enum class; simplify enumeratorsAlexey Rusakov
This enumeration sees very limited (if any) use outside Quotient; and though this change will surely break code using it the fix is very straightforward and quick.
2021-11-17Fix QDateTime(QDate) deprecation warningsAlexey Rusakov
2021-11-17Room: refactoring around logging (esp. profile logs)Alexey Rusakov
2021-11-17Merge branch 'dev' into kitsune-fix-read-receipts-and-markersAlexey Rusakov
# Conflicts: # lib/room.cpp
2021-11-17Room: lastLocalReadReceipt(), localReadReceiptMarker()Alexey Rusakov
To simplify retrieval of the local m.read receipt and the marker for it.
2021-11-17Room: doc-comments cleanupAlexey Rusakov
[skip ci]
2021-11-17Bind read receipts to userIds, not to User* valuesAlexey Rusakov
This reduces the surface interacting with the User class that eventually will be split into LocalUser (most part) and RoomMember (a tiny wrapper around the member data in a given room, used almost everywhere in Room where User currently is). Also: dropped a log message when the new receipt is at or behind the old one as it causes a lot of noise in the logs.
2021-11-16Merge pull request #520 from TobiasFella/implicitthiscaptureAlexey Rusakov
Port away from implicit 'this' captures in lambdas
2021-11-16Port away from implicit 'this' captures in lambdasTobias Fella
Deprecated with C++20
2021-11-15Port away from deprecated upfront percent encodingTobias Fella
2021-11-12Make ReceiptEvent constructible from contentAlexey Rusakov
Makes the Room::P::toJson() code more readable.
2021-11-12Fix a few quirks in converters.hAlexey Rusakov
2021-11-12Fix building with GCCAlexey Rusakov
It didn't like using QT_IGNORE_DEPRECATIONS inside a statement.
2021-11-11Fix a few quirks in converters.hAlexey Rusakov
2021-11-11Update comments around read receipts codeAlexey Rusakov
2021-11-11Merge branch 'dev' into kitsune-fix-read-receipts-and-markersAlexey Rusakov
2021-11-11DECL_DEPRECATED_ENUMERATORAlexey Rusakov
A handy macro that introduces an enumerator with a respective Q_DECL_DEPRECATED_X recommending the substitution.
2021-11-08Room::Change: deprecate AccountDataChange, ReadMarkerChangeAlexey Rusakov
These usually don't affect the room outlooks in the room list in any way; so can be merged into OtherChange instead. Also: OtherChanges synonym has been added, implying that there might be more than one change behind a single "Other" flag.