diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2021-01-12 19:26:34 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2021-01-12 19:26:34 +0100 |
commit | 7ac0bf044e521be4043c0b545d42323e2f9101a4 (patch) | |
tree | 92b9f527b8f6d8f59acd5163e1b6b7a5eafa634f /lib/eventitem.h | |
parent | 0990ab8121002e1613ac68558e07c74855370713 (diff) | |
download | libquotient-7ac0bf044e521be4043c0b545d42323e2f9101a4.tar.gz libquotient-7ac0bf044e521be4043c0b545d42323e2f9101a4.zip |
EventItemBase: Allow adding custom data
A new field of std::any type is added that allows clients to "annotate"
any event item with arbitrary kind of data. This is mainly intended so
that clients could calculate certain information about the item (e.g.
special formatting depending on the event contents, or position) without
having to calculate this information every time it is visualised.
In case of Quaternion, the idea is to calculate the "spamminess" of
the event basing on the past activity of a given user in this room -
calculating it upon displaying each event is extremely heavyweight.
Diffstat (limited to 'lib/eventitem.h')
-rw-r--r-- | lib/eventitem.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/eventitem.h b/lib/eventitem.h index 7b2c3c44..137ddf63 100644 --- a/lib/eventitem.h +++ b/lib/eventitem.h @@ -20,6 +20,7 @@ #include "events/stateevent.h" +#include <any> #include <utility> namespace Quotient { @@ -72,6 +73,12 @@ public: return std::exchange(evt, move(other)); } + /// Store arbitrary data with the event item + void setUserData(std::any userData) { data = userData; } + /// Obtain custom data previously stored with the event item + const std::any& userdata() const { return data; } + std::any& userData() { return data; } + protected: template <typename EventT> EventT* getAs() @@ -81,6 +88,7 @@ protected: private: RoomEventPtr evt; + std::any data; }; class TimelineItem : public EventItemBase { |