diff options
author | Black Hat <bhat@encom.eu.org> | 2018-09-12 21:04:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 21:04:29 +0800 |
commit | 1e78ca6b9c09cb16677ab3db1656085adbd4901b (patch) | |
tree | 633a6e8fe8a244b44b510b608ec3103431a0e042 /lib/events | |
parent | 79f338877dec3de5ec7394f190025395877cb00b (diff) | |
parent | 2a1596c16baad77fc80391c66694101f91028deb (diff) | |
download | libquotient-1e78ca6b9c09cb16677ab3db1656085adbd4901b.tar.gz libquotient-1e78ca6b9c09cb16677ab3db1656085adbd4901b.zip |
Merge pull request #1 from QMatrixClient/master
Merge to latest commit.
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/accountdataevents.h | 38 |
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>; |