diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-06 22:17:55 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-08 17:43:58 +0200 |
commit | e7a4b5a545b0f59b95ca8097009dbf6eea534db1 (patch) | |
tree | a46e434c077cba00307053169b856142304e5e41 /lib/events/accountdataevents.h | |
parent | 41f630cf7be6e806e498cb31711f403bf6919ff8 (diff) | |
download | libquotient-e7a4b5a545b0f59b95ca8097009dbf6eea534db1.tar.gz libquotient-e7a4b5a545b0f59b95ca8097009dbf6eea534db1.zip |
Generalise DEFINE_SIMPLE_EVENT
This macro was defined in accountdataevents.h but adding one more
parameter (base class) makes it applicable to pretty much any event
with the content that has one key-value pair (though state events
already have a non-macro solution in the form of
`StateEvent<EventContent::SingleKeyValue>`). Now CustomEvent definition
in quotest.cpp can be replaced with a single line.
Diffstat (limited to 'lib/events/accountdataevents.h')
-rw-r--r-- | lib/events/accountdataevents.h | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h index 12f1f00b..ec2f64e3 100644 --- a/lib/events/accountdataevents.h +++ b/lib/events/accountdataevents.h @@ -46,27 +46,14 @@ struct JsonObjectConverter<TagRecord> { using TagsMap = QHash<QString, TagRecord>; -#define DEFINE_SIMPLE_EVENT(_Name, _TypeId, _ContentType, _ContentKey) \ - class QUOTIENT_API _Name : public Event { \ - public: \ - using content_type = _ContentType; \ - DEFINE_EVENT_TYPEID(_TypeId, _Name) \ - explicit _Name(const QJsonObject& obj) : Event(typeId(), obj) {} \ - explicit _Name(const content_type& content) \ - : Event(typeId(), matrixTypeId(), \ - QJsonObject { \ - { QStringLiteral(#_ContentKey), toJson(content) } }) \ - {} \ - auto _ContentKey() const \ - { \ - return contentPart<content_type>(#_ContentKey##_ls); \ - } \ - }; \ - REGISTER_EVENT_TYPE(_Name) \ - // End of macro - -DEFINE_SIMPLE_EVENT(TagEvent, "m.tag", TagsMap, tags) -DEFINE_SIMPLE_EVENT(ReadMarkerEvent, "m.fully_read", QString, event_id) -DEFINE_SIMPLE_EVENT(IgnoredUsersEvent, "m.ignored_user_list", QSet<QString>, +DEFINE_SIMPLE_EVENT(TagEvent, Event, "m.tag", TagsMap, tags) +DEFINE_SIMPLE_EVENT(ReadMarkerEventImpl, Event, "m.fully_read", QString, eventId) +class ReadMarkerEvent : public ReadMarkerEventImpl { +public: + using ReadMarkerEventImpl::ReadMarkerEventImpl; + [[deprecated("Use ReadMarkerEvent::eventId() instead")]] + QString event_id() const { return eventId(); } +}; +DEFINE_SIMPLE_EVENT(IgnoredUsersEvent, Event, "m.ignored_user_list", QSet<QString>, ignored_users) } // namespace Quotient |