From aacc4bcb4a487871daae6717f77605aaba444341 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:26:57 +0100 Subject: style: apply .clang-format to all .cpp and .h files --- lib/syncdata.cpp | 122 ++++++++++++++++++++++++------------------------------- 1 file changed, 53 insertions(+), 69 deletions(-) (limited to 'lib/syncdata.cpp') diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index f55d4396..d8fb7bb6 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -13,7 +13,7 @@ * * 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 */ #include "syncdata.h" @@ -30,17 +30,16 @@ const QString SyncRoomData::UnreadCountKey = bool RoomSummary::isEmpty() const { - return joinedMemberCount.omitted() && invitedMemberCount.omitted() && - heroes.omitted(); + return joinedMemberCount.omitted() && invitedMemberCount.omitted() + && heroes.omitted(); } bool RoomSummary::merge(const RoomSummary& other) { // Using bitwise OR to prevent computation shortcut. - return - joinedMemberCount.merge(other.joinedMemberCount) | - invitedMemberCount.merge(other.invitedMemberCount) | - heroes.merge(other.heroes); + return joinedMemberCount.merge(other.joinedMemberCount) + | invitedMemberCount.merge(other.invitedMemberCount) + | heroes.merge(other.heroes); } QDebug QMatrixClient::operator<<(QDebug dbg, const RoomSummary& rs) @@ -78,32 +77,33 @@ void JsonObjectConverter::fillFrom(const QJsonObject& jo, template inline EventsArrayT load(const QJsonObject& batches, StrT keyName) { - return fromJson(batches[keyName].toObject().value("events"_ls)); + return fromJson( + batches[keyName].toObject().value("events"_ls)); } SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const QJsonObject& room_) - : roomId(roomId_) - , joinState(joinState_) - , summary(fromJson(room_["summary"])) - , state(load(room_, joinState == JoinState::Invite - ? "invite_state"_ls : "state"_ls)) + : roomId(roomId_), + joinState(joinState_), + summary(fromJson(room_["summary"])), + state(load(room_, + joinState == JoinState::Invite ? "invite_state"_ls + : "state"_ls)) { switch (joinState) { - case JoinState::Join: - ephemeral = load(room_, "ephemeral"_ls); - FALLTHROUGH; - case JoinState::Leave: - { - accountData = load(room_, "account_data"_ls); - timeline = load(room_, "timeline"_ls); - const auto timelineJson = room_.value("timeline"_ls).toObject(); - timelineLimited = timelineJson.value("limited"_ls).toBool(); - timelinePrevBatch = timelineJson.value("prev_batch"_ls).toString(); - - break; - } - default: /* nothing on top of state */; + case JoinState::Join: + ephemeral = load(room_, "ephemeral"_ls); + FALLTHROUGH; + case JoinState::Leave: { + accountData = load(room_, "account_data"_ls); + timeline = load(room_, "timeline"_ls); + const auto timelineJson = room_.value("timeline"_ls).toObject(); + timelineLimited = timelineJson.value("limited"_ls).toBool(); + timelinePrevBatch = timelineJson.value("prev_batch"_ls).toString(); + + break; + } + default: /* nothing on top of state */; } const auto unreadJson = room_.value("unread_notifications"_ls).toObject(); @@ -121,20 +121,17 @@ SyncData::SyncData(const QString& cacheFileName) QFileInfo cacheFileInfo { cacheFileName }; auto json = loadJson(cacheFileName); auto requiredVersion = std::get<0>(cacheVersion()); - auto actualVersion = json.value("cache_version").toObject() - .value("major").toInt(); + auto actualVersion = + json.value("cache_version").toObject().value("major").toInt(); if (actualVersion == requiredVersion) parseJson(json, cacheFileInfo.absolutePath() + '/'); else - qCWarning(MAIN) - << "Major version of the cache file is" << actualVersion << "but" - << requiredVersion << "is required; discarding the cache"; + qCWarning(MAIN) << "Major version of the cache file is" << actualVersion + << "but" << requiredVersion + << "is required; discarding the cache"; } -SyncDataList&& SyncData::takeRoomData() -{ - return move(roomData); -} +SyncDataList&& SyncData::takeRoomData() { return move(roomData); } QString SyncData::fileNameForRoom(QString roomId) { @@ -142,31 +139,20 @@ QString SyncData::fileNameForRoom(QString roomId) return roomId + ".json"; } -Events&& SyncData::takePresenceData() -{ - return std::move(presenceData); -} +Events&& SyncData::takePresenceData() { return std::move(presenceData); } -Events&& SyncData::takeAccountData() -{ - return std::move(accountData); -} +Events&& SyncData::takeAccountData() { return std::move(accountData); } -Events&& SyncData::takeToDeviceEvents() -{ - return std::move(toDeviceEvents); -} +Events&& SyncData::takeToDeviceEvents() { return std::move(toDeviceEvents); } QJsonObject SyncData::loadJson(const QString& fileName) { QFile roomFile { fileName }; - if (!roomFile.exists()) - { + if (!roomFile.exists()) { qCWarning(MAIN) << "No state cache file" << fileName; return {}; } - if(!roomFile.open(QIODevice::ReadOnly)) - { + if (!roomFile.open(QIODevice::ReadOnly)) { qCWarning(MAIN) << "Failed to open state cache file" << roomFile.fileName(); return {}; @@ -174,10 +160,10 @@ QJsonObject SyncData::loadJson(const QString& fileName) auto data = roomFile.readAll(); const auto json = - (data.startsWith('{') ? QJsonDocument::fromJson(data) - : QJsonDocument::fromBinaryData(data)).object(); - if (json.isEmpty()) - { + (data.startsWith('{') ? QJsonDocument::fromJson(data) + : QJsonDocument::fromBinaryData(data)) + .object(); + if (json.isEmpty()) { qCWarning(MAIN) << "State cache in" << fileName << "is broken or empty, discarding"; } @@ -186,7 +172,8 @@ QJsonObject SyncData::loadJson(const QString& fileName) void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) { - QElapsedTimer et; et.start(); + QElapsedTimer et; + et.start(); nextBatch_ = json.value("next_batch"_ls).toString(); presenceData = load(json, "presence"_ls); @@ -197,25 +184,22 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) JoinStates::Int ii = 1; // ii is used to make a JoinState value auto totalRooms = 0; auto totalEvents = 0; - for (size_t i = 0; i < JoinStateStrings.size(); ++i, ii <<= 1) - { + for (size_t i = 0; i < JoinStateStrings.size(); ++i, ii <<= 1) { 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(rs.size())); - for(auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) - { + for (auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) { auto roomJson = roomIt->isObject() - ? roomIt->toObject() - : loadJson(baseDir + fileNameForRoom(roomIt.key())); - if (roomJson.isEmpty()) - { + ? roomIt->toObject() + : loadJson(baseDir + fileNameForRoom(roomIt.key())); + if (roomJson.isEmpty()) { unresolvedRoomIds.push_back(roomIt.key()); continue; } roomData.emplace_back(roomIt.key(), JoinState(ii), roomJson); const auto& r = roomData.back(); - totalEvents += r.state.size() + r.ephemeral.size() + - r.accountData.size() + r.timeline.size(); + totalEvents += r.state.size() + r.ephemeral.size() + + r.accountData.size() + r.timeline.size(); } totalRooms += rs.size(); } @@ -223,6 +207,6 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) qCWarning(MAIN) << "Unresolved rooms:" << unresolvedRoomIds.join(','); if (totalRooms > 9 || et.nsecsElapsed() >= profilerMinNsecs()) qCDebug(PROFILER) << "*** SyncData::parseJson(): batch with" - << totalRooms << "room(s)," - << totalEvents << "event(s) in" << et; + << totalRooms << "room(s)," << totalEvents + << "event(s) in" << et; } -- cgit v1.2.3