diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 8 | ||||
-rw-r--r-- | lib/connection.h | 6 | ||||
-rw-r--r-- | lib/room.cpp | 8 | ||||
-rw-r--r-- | lib/room.h | 6 |
4 files changed, 18 insertions, 10 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 600ab396..241fa43d 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -84,7 +84,7 @@ class Connection::Private QVector<QString> roomIdsToForget; QMap<QString, User*> userMap; DirectChatsMap directChats; - QHash<QString, QVariantHash> accountData; + QHash<QString, AccountDataMap> accountData; QString userId; SyncJob* syncJob = nullptr; @@ -336,7 +336,7 @@ void Connection::onSyncSuccess(SyncData &&data) { continue; } d->accountData[accountEvent->jsonType()] = - accountEvent->contentJson().toVariantHash(); + fromJson<AccountDataMap>(accountEvent->contentJson()); emit accountDataChanged(accountEvent->jsonType()); } } @@ -657,7 +657,7 @@ bool Connection::hasAccountData(const QString& type) const return d->accountData.contains(type); } -QVariantHash Connection::accountData(const QString& type) const +Connection::AccountDataMap Connection::accountData(const QString& type) const { return d->accountData.value(type); } @@ -909,7 +909,7 @@ void Connection::saveState(const QUrl &toFile) const for (auto it = d->accountData.begin(); it != d->accountData.end(); ++it) accountDataEvents.append(QJsonObject { {"type", it.key()}, - {"content", QJsonObject::fromVariantHash(it.value())} + {"content", QMatrixClient::toJson(it.value())} }); rootObj.insert("account_data", QJsonObject {{ QStringLiteral("events"), accountDataEvents }}); diff --git a/lib/connection.h b/lib/connection.h index be414931..839371ef 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -66,6 +66,10 @@ namespace QMatrixClient using DirectChatsMap = QMultiHash<const User*, QString>; + using AccountDataMap = std::conditional_t< + QT_VERSION >= QT_VERSION_CHECK(5, 5, 0), + QVariantHash, QVariantMap>; + enum RoomVisibility { PublishRoom, UnpublishRoom }; // FIXME: Should go inside CreateRoomJob explicit Connection(QObject* parent = nullptr); @@ -88,7 +92,7 @@ namespace QMatrixClient * stored on the server. Direct chats map cannot be retrieved * using this method _yet_; use directChats() instead. */ - QVariantHash accountData(const QString& type) const; + AccountDataMap accountData(const QString& type) const; /** Get all Invited and Joined rooms grouped by tag * \return a hashmap from tag name to a vector of room pointers, diff --git a/lib/room.cpp b/lib/room.cpp index edbc9266..42d63574 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -109,7 +109,7 @@ class Room::Private QHash<const User*, QString> lastReadEventIds; QString serverReadMarker; TagsMap tags; - QHash<QString, QVariantHash> accountData; + QHash<QString, AccountDataMap> accountData; QString prevBatch; QPointer<RoomMessagesJob> roomMessagesJob; @@ -637,7 +637,7 @@ bool Room::hasAccountData(const QString& type) const return d->accountData.contains(type); } -QVariantHash Room::accountData(const QString& type) const +Room::AccountDataMap Room::accountData(const QString& type) const { return d->accountData.value(type); } @@ -1653,7 +1653,7 @@ void Room::processAccountDataEvent(EventPtr event) } default: d->accountData[event->jsonType()] = - event->contentJson().toVariantHash(); + fromJson<AccountDataMap>(event->contentJson()); emit accountDataChanged(event->jsonType()); } } @@ -1816,7 +1816,7 @@ QJsonObject Room::Private::toJson() const { for (auto it = accountData.begin(); it != accountData.end(); ++it) appendEvent(accountDataEvents, it.key(), - QJsonObject::fromVariantHash(it.value())); + QMatrixClient::toJson(it.value())); } result.insert("account_data", QJsonObject {{ "events", accountDataEvents }}); @@ -123,6 +123,10 @@ namespace QMatrixClient using rev_iter_t = Timeline::const_reverse_iterator; using timeline_iter_t = Timeline::const_iterator; + using AccountDataMap = std::conditional_t< + QT_VERSION >= QT_VERSION_CHECK(5, 5, 0), + QVariantHash, QVariantMap>; + Room(Connection* connection, QString id, JoinState initialJoinState); ~Room() override; @@ -269,7 +273,7 @@ namespace QMatrixClient * stored on the server. Tags and read markers cannot be retrieved * using this method _yet_. */ - QVariantHash accountData(const QString& type) const; + AccountDataMap accountData(const QString& type) const; QStringList tagNames() const; TagsMap tags() const; |