aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jobs/syncjob.cpp12
-rw-r--r--joinstate.h16
2 files changed, 17 insertions, 11 deletions
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 6d37db5c..ce5dd894 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -69,19 +69,13 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data)
// TODO: account_data
QJsonObject rooms = json.value("rooms").toObject();
- static const struct { QString jsonKey; JoinState enumVal; } roomStates[]
+ for (size_t i = 0; i < JoinStateStrings.size(); ++i)
{
- { "join", JoinState::Join },
- { "invite", JoinState::Invite },
- { "leave", JoinState::Leave }
- };
- for (const auto& roomState: roomStates)
- {
- const QJsonObject rs = rooms.value(roomState.jsonKey).toObject();
+ const auto rs = rooms.value(JoinStateStrings[i]).toObject();
// We have a Qt container on the right and an STL one on the left
roomData.reserve(static_cast<size_t>(rs.size()));
for(auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt)
- roomData.emplace_back(roomIt.key(), roomState.enumVal,
+ roomData.emplace_back(roomIt.key(), JoinState(i),
roomIt.value().toObject());
}
qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms";
diff --git a/joinstate.h b/joinstate.h
index 348ca8a6..cfdb90f2 100644
--- a/joinstate.h
+++ b/joinstate.h
@@ -18,12 +18,24 @@
#pragma once
+#include <array>
+
namespace QMatrixClient
{
enum class JoinState
{
- Join,
+ Join = 0,
Invite,
Leave
};
-}
+
+ // We cannot use REGISTER_ENUM outside of a Q_OBJECT and besides, we want
+ // to use strings that match respective JSON keys.
+ static constexpr std::array<const char*, 3> JoinStateStrings
+ { { "join", "invite", "leave" } };
+
+ inline constexpr const char* toCString(JoinState js)
+ {
+ return JoinStateStrings[size_t(js)];
+ }
+} // namespace QMatrixClient