aboutsummaryrefslogtreecommitdiff
path: root/lib/events/accountdataevents.h
diff options
context:
space:
mode:
authorAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
committerAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
commit09eb39236666e81d5da014acea011dcd74d0999b (patch)
tree52876d96be71be1a39d5d935c1295a51995e8949 /lib/events/accountdataevents.h
parentf1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff)
parenta4e78956f105875625b572d8b98459ffa86fafe5 (diff)
downloadlibquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz
libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4' with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/events/accountdataevents.h')
-rw-r--r--lib/events/accountdataevents.h127
1 files changed, 59 insertions, 68 deletions
diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h
index a43e358c..a55016d9 100644
--- a/lib/events/accountdataevents.h
+++ b/lib/events/accountdataevents.h
@@ -1,5 +1,3 @@
-#include <utility>
-
/******************************************************************************
* Copyright (C) 2018 Kitsune Ral <kitsune-ral@users.sf.net>
*
@@ -15,87 +13,80 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
+#include "converters.h"
#include "event.h"
#include "eventcontent.h"
-#include "converters.h"
-namespace QMatrixClient
-{
- constexpr const char* FavouriteTag = "m.favourite";
- constexpr const char* LowPriorityTag = "m.lowpriority";
- constexpr const char* ServerNoticeTag = "m.server_notice";
+namespace Quotient {
+constexpr const char* FavouriteTag = "m.favourite";
+constexpr const char* LowPriorityTag = "m.lowpriority";
+constexpr const char* ServerNoticeTag = "m.server_notice";
- struct TagRecord
- {
- using order_type = Omittable<float>;
+struct TagRecord {
+ using order_type = Omittable<float>;
- order_type order;
+ order_type order;
- TagRecord (order_type order = none) : order(order) { }
+ TagRecord(order_type order = none) : order(std::move(order)) {}
- bool operator<(const TagRecord& other) const
- {
- // Per The Spec, rooms with no order should be after those with order
- return !order.omitted() &&
- (other.order.omitted() || order.value() < other.order.value());
- }
- };
+ bool operator<(const TagRecord& other) const
+ {
+ // Per The Spec, rooms with no order should be after those with order,
+ // against optional<>::operator<() convention.
+ return order && (!other.order || *order < *other.order);
+ }
+};
- template <> struct JsonObjectConverter<TagRecord>
+template <>
+struct JsonObjectConverter<TagRecord> {
+ static void fillFrom(const QJsonObject& jo, TagRecord& rec)
{
- static void fillFrom(const QJsonObject& jo, TagRecord& rec)
- {
- // Parse a float both from JSON double and JSON string because
- // libqmatrixclient previously used to use strings to store order.
- const auto orderJv = jo.value("order"_ls);
- if (orderJv.isDouble())
- rec.order = fromJson<float>(orderJv);
- if (orderJv.isString())
- {
- bool ok;
- rec.order = orderJv.toString().toFloat(&ok);
- if (!ok)
- rec.order = none;
- }
- }
- static void dumpTo(QJsonObject& jo, const TagRecord& rec)
- {
- addParam<IfNotEmpty>(jo, QStringLiteral("order"), rec.order);
+ // Parse a float both from JSON double and JSON string because
+ // the library previously used to use strings to store order.
+ const auto orderJv = jo.value("order"_ls);
+ if (orderJv.isDouble())
+ rec.order = fromJson<float>(orderJv);
+ if (orderJv.isString()) {
+ bool ok;
+ rec.order = orderJv.toString().toFloat(&ok);
+ if (!ok)
+ rec.order = none;
}
- };
+ }
+ static void dumpTo(QJsonObject& jo, const TagRecord& rec)
+ {
+ addParam<IfNotEmpty>(jo, QStringLiteral("order"), rec.order);
+ }
+};
- using TagsMap = QHash<QString, TagRecord>;
+using TagsMap = QHash<QString, TagRecord>;
-#define DEFINE_SIMPLE_EVENT(_Name, _TypeId, _ContentType, _ContentKey) \
- class _Name : public Event \
- { \
- public: \
- using content_type = _ContentType; \
- DEFINE_EVENT_TYPEID(_TypeId, _Name) \
- explicit _Name(QJsonObject obj) \
- : Event(typeId(), std::move(obj)) \
- { } \
- explicit _Name(_ContentType content) \
- : Event(typeId(), matrixTypeId(), \
- QJsonObject { { QStringLiteral(#_ContentKey), \
- toJson(std::move(content)) } }) \
- { } \
- auto _ContentKey() const \
- { return fromJson<content_type>(contentJson()[#_ContentKey##_ls]); } \
- }; \
- REGISTER_EVENT_TYPE(_Name) \
+#define DEFINE_SIMPLE_EVENT(_Name, _TypeId, _ContentType, _ContentKey) \
+ class _Name : public Event { \
+ public: \
+ using content_type = _ContentType; \
+ DEFINE_EVENT_TYPEID(_TypeId, _Name) \
+ explicit _Name(QJsonObject obj) : Event(typeId(), std::move(obj)) {} \
+ explicit _Name(_ContentType content) \
+ : Event(typeId(), matrixTypeId(), \
+ QJsonObject { { QStringLiteral(#_ContentKey), \
+ toJson(std::move(content)) } }) \
+ {} \
+ auto _ContentKey() const \
+ { \
+ return content<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>, ignored_users)
-
- DEFINE_EVENTTYPE_ALIAS(Tag, TagEvent)
- DEFINE_EVENTTYPE_ALIAS(ReadMarker, ReadMarkerEvent)
-}
+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>,
+ ignored_users)
+} // namespace Quotient