aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/accountdataevents.h38
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h
index 94fc510a..27f6c77c 100644
--- a/lib/events/accountdataevents.h
+++ b/lib/events/accountdataevents.h
@@ -31,22 +31,40 @@ namespace QMatrixClient
struct TagRecord
{
- TagRecord (QString order = {}) : order(std::move(order)) { }
- explicit TagRecord(const QJsonValue& jv)
- : order(jv.toObject().value("order"_ls).toString())
- { }
+ using order_type = Omittable<float>;
+
+ order_type order;
- QString order;
+ TagRecord (order_type order = none) : order(order) { }
+ explicit TagRecord(const QJsonValue& jv)
+ {
+ // Parse a float both from JSON double and JSON string because
+ // libqmatrixclient previously used to use strings to store order.
+ const auto orderJv = jv.toObject().value("order"_ls);
+ if (orderJv.isDouble())
+ order = fromJson<float>(orderJv);
+ else if (orderJv.isString())
+ {
+ bool ok;
+ order = orderJv.toString().toFloat(&ok);
+ if (!ok)
+ order = none;
+ }
+ }
- bool operator==(const TagRecord& other) const
- { return order == other.order; }
- bool operator!=(const TagRecord& other) const
- { return !operator==(other); }
+ 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());
+ }
};
inline QJsonValue toJson(const TagRecord& rec)
{
- return QJsonObject {{ QStringLiteral("order"), rec.order }};
+ QJsonObject o;
+ addParam(o, QStringLiteral("order"), rec.order);
+ return o;
}
using TagsMap = QHash<QString, TagRecord>;