diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 2 | ||||
-rw-r--r-- | lib/connection.h | 2 | ||||
-rw-r--r-- | lib/events/accountdataevents.h | 18 | ||||
-rw-r--r-- | lib/events/event.h | 46 | ||||
-rw-r--r-- | lib/events/reactionevent.h | 17 | ||||
-rw-r--r-- | lib/events/typingevent.cpp | 11 | ||||
-rw-r--r-- | lib/events/typingevent.h | 10 | ||||
-rw-r--r-- | lib/room.cpp | 2 |
8 files changed, 42 insertions, 66 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 79d7ae55..722829e8 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -1701,7 +1701,7 @@ bool Connection::isIgnored(const User* user) const IgnoredUsersList Connection::ignoredUsers() const { const auto* event = accountData<IgnoredUsersEvent>(); - return event ? event->ignored_users() : IgnoredUsersList(); + return event ? event->ignoredUsers() : IgnoredUsersList(); } void Connection::addToIgnoredUsers(const User* user) diff --git a/lib/connection.h b/lib/connection.h index 39921938..66ed8b68 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -111,7 +111,7 @@ auto defaultUserFactory(Connection* c, const QString& id) // are stored with no regard to their state. using DirectChatsMap = QMultiHash<const User*, QString>; using DirectChatUsersMap = QMultiHash<QString, User*>; -using IgnoredUsersList = IgnoredUsersEvent::content_type; +using IgnoredUsersList = IgnoredUsersEvent::value_type; class QUOTIENT_API Connection : public QObject { Q_OBJECT diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h index 24c3353c..324ce449 100644 --- a/lib/events/accountdataevents.h +++ b/lib/events/accountdataevents.h @@ -4,7 +4,6 @@ #pragma once #include "event.h" -#include "util.h" namespace Quotient { constexpr auto FavouriteTag [[maybe_unused]] = "m.favourite"_ls; @@ -46,14 +45,21 @@ struct JsonObjectConverter<TagRecord> { using TagsMap = QHash<QString, TagRecord>; -DEFINE_SIMPLE_EVENT(TagEvent, Event, "m.tag", TagsMap, tags) -DEFINE_SIMPLE_EVENT(ReadMarkerEventImpl, Event, "m.fully_read", QString, eventId) +DEFINE_SIMPLE_EVENT(TagEvent, Event, "m.tag", TagsMap, tags, "tags") +DEFINE_SIMPLE_EVENT(ReadMarkerEventImpl, Event, "m.fully_read", QString, + eventId, "event_id") class ReadMarkerEvent : public ReadMarkerEventImpl { public: using ReadMarkerEventImpl::ReadMarkerEventImpl; [[deprecated("Use ReadMarkerEvent::eventId() instead")]] - QString event_id() const { return eventId(); } + auto event_id() const { return eventId(); } +}; +DEFINE_SIMPLE_EVENT(IgnoredUsersEventImpl, Event, "m.ignored_user_list", + QSet<QString>, ignoredUsers, "ignored_users") +class IgnoredUsersEvent : public IgnoredUsersEventImpl { +public: + using IgnoredUsersEventImpl::IgnoredUsersEventImpl; + [[deprecated("Use IgnoredUsersEvent::ignoredUsers() instead")]] + auto ignored_users() const { return ignoredUsers(); } }; -DEFINE_SIMPLE_EVENT(IgnoredUsersEvent, Event, "m.ignored_user_list", QSet<QString>, - ignored_users) } // namespace Quotient diff --git a/lib/events/event.h b/lib/events/event.h index b7454337..711f8fd4 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -6,6 +6,7 @@ #include "converters.h" #include "logging.h" #include "function_traits.h" +#include "single_key_value.h" namespace Quotient { // === event_ptr_tt<> and type casting facilities === @@ -258,6 +259,13 @@ template <typename EventT> using EventsArray = std::vector<event_ptr_tt<EventT>>; using Events = EventsArray<Event>; +#define QUO_CONTENT_GETTER_X(PartType_, PartName_, JsonKey_) \ + PartType_ PartName_() const \ + { \ + static const auto PartName_##JsonKey = JsonKey_; \ + return contentPart<PartType_>(PartName_##JsonKey); \ + } + //! \brief Define an inline method obtaining a content part //! //! This macro adds a const method that extracts a JSON value at the key @@ -266,12 +274,8 @@ using Events = EventsArray<Event>; //! \code //! contentPart<PartType_>(Quotient::toSnakeCase(#PartName_##_ls)); //! \endcode -#define QUO_CONTENT_GETTER(PartType_, PartName_) \ - PartType_ PartName_() const \ - { \ - static const auto JsonKey = toSnakeCase(#PartName_##_ls); \ - return contentPart<PartType_>(JsonKey); \ - } +#define QUO_CONTENT_GETTER(PartType_, PartName_) \ + QUO_CONTENT_GETTER_X(PartType_, PartName_, toSnakeCase(#PartName_##_ls)) // === Facilities for event class definitions === @@ -301,22 +305,20 @@ using Events = EventsArray<Event>; /// To retrieve the value the getter uses a JSON key name that corresponds to /// its own (getter's) name but written in snake_case. \p GetterName_ must be /// in camelCase, no quotes (an identifier, not a literal). -#define DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_) \ - class QUOTIENT_API Name_ : public Base_ { \ - public: \ - using content_type = ValueType_; \ - DEFINE_EVENT_TYPEID(TypeId_, Name_) \ - explicit Name_(const QJsonObject& obj) : Base_(TypeId, obj) {} \ - explicit Name_(const content_type& content) \ - : Name_(Base_::basicJson(TypeId, { { JsonKey, toJson(content) } })) \ - {} \ - auto GetterName_() const \ - { \ - return contentPart<content_type>(JsonKey); \ - } \ - static inline const auto JsonKey = toSnakeCase(#GetterName_##_ls); \ - }; \ - REGISTER_EVENT_TYPE(Name_) \ +#define DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_, \ + JsonKey_) \ + class QUOTIENT_API Name_ : public Base_ { \ + public: \ + DEFINE_EVENT_TYPEID(TypeId_, Name_) \ + using value_type = ValueType_; \ + explicit Name_(const QJsonObject& obj) : Base_(TypeId, obj) {} \ + explicit Name_(const value_type& v) \ + : Name_(Base_::basicJson(TypeId, { { JsonKey, toJson(v) } })) \ + {} \ + QUO_CONTENT_GETTER_X(ValueType_, GetterName_, JsonKey) \ + static inline const auto JsonKey = toSnakeCase(#GetterName_##_ls); \ + }; \ + REGISTER_EVENT_TYPE(Name_) \ // End of macro // === is<>(), eventCast<>() and switchOnType<>() === diff --git a/lib/events/reactionevent.h b/lib/events/reactionevent.h index b3cb3ca7..8d873441 100644 --- a/lib/events/reactionevent.h +++ b/lib/events/reactionevent.h @@ -8,20 +8,7 @@ namespace Quotient { -class QUOTIENT_API ReactionEvent : public RoomEvent { -public: - DEFINE_EVENT_TYPEID("m.reaction", ReactionEvent) - - explicit ReactionEvent(const EventRelation& value) - : RoomEvent(typeId(), matrixTypeId(), - { { QStringLiteral("m.relates_to"), toJson(value) } }) - {} - explicit ReactionEvent(const QJsonObject& obj) : RoomEvent(typeId(), obj) {} - EventRelation relation() const - { - return contentPart<EventRelation>(RelatesToKey); - } -}; -REGISTER_EVENT_TYPE(ReactionEvent) +DEFINE_SIMPLE_EVENT(ReactionEvent, RoomEvent, "m.reaction", EventRelation, + relation, "m.relates_to") } // namespace Quotient diff --git a/lib/events/typingevent.cpp b/lib/events/typingevent.cpp deleted file mode 100644 index 7e5d7ee6..00000000 --- a/lib/events/typingevent.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2017 Kitsune Ral <Kitsune-Ral@users.sf.net> -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "typingevent.h" - -using namespace Quotient; - -QStringList TypingEvent::users() const -{ - return contentPart<QStringList>("user_ids"_ls); -} diff --git a/lib/events/typingevent.h b/lib/events/typingevent.h index 522f7e42..b56475af 100644 --- a/lib/events/typingevent.h +++ b/lib/events/typingevent.h @@ -6,13 +6,5 @@ #include "event.h" namespace Quotient { -class QUOTIENT_API TypingEvent : public Event { -public: - DEFINE_EVENT_TYPEID("m.typing", TypingEvent) - - explicit TypingEvent(const QJsonObject& obj) : Event(typeId(), obj) {} - - QStringList users() const; -}; -REGISTER_EVENT_TYPE(TypingEvent) +DEFINE_SIMPLE_EVENT(TypingEvent, Event, "m.typing", QStringList, users, "user_ids") } // namespace Quotient diff --git a/lib/room.cpp b/lib/room.cpp index ebc6e6af..4cae2333 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -3294,7 +3294,7 @@ Room::Changes Room::processAccountDataEvent(EventPtr&& event) } if (auto* evt = eventCast<const ReadMarkerEvent>(event)) - changes |= d->setFullyReadMarker(evt->event_id()); + changes |= d->setFullyReadMarker(evt->eventId()); // For all account data events auto& currentData = d->accountData[event->matrixType()]; |