diff options
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/syncdata.cpp | 13 | ||||
-rw-r--r-- | lib/user.cpp | 10 |
3 files changed, 18 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index db5eafe5..1e207478 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,11 @@ message( STATUS ) # Set up source files set(lib_SRCS + # This .h is special in that it declares a Q_NAMESPACE but has no .cpp + # where staticMetaObject for that namespace would be defined; passing it + # to add_library (see below) puts it on the automoc radar, producing + # a compilation unit with the needed definition. + lib/quotient_common.h lib/networkaccessmanager.cpp lib/connectiondata.cpp lib/connection.cpp diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index e6472e18..64aa65fd 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -186,13 +186,18 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) deviceOneTimeKeysCount_); auto rooms = json.value("rooms"_ls).toObject(); - 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) { + // The first comparison shortcuts the loop when not all states are there + // in the response (anything except "join" is only occasional, and "join" + // intentionally comes first in the enum). + for (size_t i = 0; int(i) < rooms.size() && i < JoinStateStrings.size(); + ++i) { + // This assumes that JoinState values go over powers of 2: 1,2,4,... + const auto joinState = JoinState(1U << i); 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())); + roomData.reserve(roomData.size() + static_cast<size_t>(rs.size())); for (auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) { auto roomJson = roomIt->isObject() @@ -202,7 +207,7 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) unresolvedRoomIds.push_back(roomIt.key()); continue; } - roomData.emplace_back(roomIt.key(), JoinState(ii), roomJson); + roomData.emplace_back(roomIt.key(), joinState, roomJson); const auto& r = roomData.back(); totalEvents += r.state.size() + r.ephemeral.size() + r.accountData.size() + r.timeline.size(); diff --git a/lib/user.cpp b/lib/user.cpp index 7143620f..f0831733 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -171,13 +171,11 @@ void User::rename(const QString& newName, const Room* r) rename(newName); return; } - Q_ASSERT_X(r->memberJoinState(this) == JoinState::Join, __FUNCTION__, + // #481: take the current state and update it with the new name + auto evtC = r->getCurrentState<RoomMemberEvent>(id())->content(); + Q_ASSERT_X(evtC.membership == MembershipType::Join, __FUNCTION__, "Attempt to rename a user that's not a room member"); - const auto actualNewName = sanitized(newName); - MemberEventContent evtC; - evtC.displayName = actualNewName; - // #481: fill in the current avatar URL in order to not clear it out - evtC.avatarUrl = r->getCurrentState<RoomMemberEvent>(id())->avatarUrl(); + evtC.displayName = sanitized(newName); r->setState<RoomMemberEvent>(id(), move(evtC)); // The state will be updated locally after it arrives with sync } |