aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-11-09 20:44:52 +0100
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-11-09 20:44:52 +0100
commit2162cc8c6b026bbdf077f0b51a89a38e20963cd6 (patch)
tree31df8efe0fcecc6e03106478f8c1f45ce4e755c9 /lib/room.cpp
parent398304961570f78019ddeb545c2cc5f18b6dd706 (diff)
downloadlibquotient-2162cc8c6b026bbdf077f0b51a89a38e20963cd6.tar.gz
libquotient-2162cc8c6b026bbdf077f0b51a89a38e20963cd6.zip
Room: be more robust in Release mode
...in one particular case, when trying to add a user to a room it's already a member of.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 90dca127..2599e036 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1346,6 +1346,11 @@ void Room::Private::insertMemberIntoMap(User* u)
// Callers should check they are not adding an existing user once more.
Q_ASSERT(!namesakes.contains(u));
+ if (namesakes.contains(u)) { // Release version whines but continues
+ qCCritical(STATE) << "Trying to add a user" << u->id() << "to room"
+ << q->objectName() << "but that's already in it";
+ return;
+ }
if (namesakes.size() == 1)
emit q->memberAboutToRename(namesakes.front(),
@@ -2402,8 +2407,8 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
const auto*& curStateEvent =
d->currentState[{ e.matrixType(), e.stateKey() }];
// Prepare for the state change
- visit(e, [this, oldRme = static_cast<const RoomMemberEvent*>(curStateEvent)](
- const RoomMemberEvent& rme) {
+ const auto oldRme = static_cast<const RoomMemberEvent*>(curStateEvent);
+ visit(e, [this, &oldRme](const RoomMemberEvent& rme) {
auto* u = user(rme.userId());
if (!u) { // ???
qCCritical(MAIN)
@@ -2506,23 +2511,20 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
emit avatarChanged();
return AvatarChange;
}
- , [this,oldStateEvent] (const RoomMemberEvent& evt) {
+ , [this,oldRme] (const RoomMemberEvent& evt) {
// clang-format on
auto* u = user(evt.userId());
- const auto* oldMemberEvent =
- static_cast<const RoomMemberEvent*>(oldStateEvent);
// TODO: remove in 0.7
- u->processEvent(evt, this, oldMemberEvent == nullptr);
+ u->processEvent(evt, this, oldRme == nullptr);
- const auto prevMembership = oldMemberEvent
- ? oldMemberEvent->membership()
- : MembershipType::Leave;
+ const auto prevMembership = oldRme ? oldRme->membership()
+ : MembershipType::Leave;
switch (evt.membership()) {
case MembershipType::Join:
if (prevMembership != MembershipType::Join) {
d->insertMemberIntoMap(u);
emit userAdded(u);
- } else if (oldMemberEvent->displayName() != evt.displayName()) {
+ } else if (oldRme->displayName() != evt.displayName()) {
d->insertMemberIntoMap(u);
emit memberRenamed(u);
}