From 39a8150faea00a6ba6202df3f0bc1a0bb4868646 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 12 Mar 2018 00:15:06 +0200 Subject: [PATCH] Update room name & avatar on new rooms fixes #253 --- include/RoomState.h | 4 ++-- src/RoomList.cc | 10 ++-------- src/RoomState.cc | 39 ++++++++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/include/RoomState.h b/include/RoomState.h index 976e0079..edef2f5a 100644 --- a/include/RoomState.h +++ b/include/RoomState.h @@ -110,8 +110,8 @@ RoomState::updateFromEvents(const std::vector &collection) } else if (mpark::holds_alternative(event)) { this->name = mpark::get(event); } else if (mpark::holds_alternative(event)) { - auto membership = mpark::get(event); - this->memberships.emplace(membership.state_key, membership); + auto membership = mpark::get(event); + memberships[membership.state_key] = membership; } else if (mpark::holds_alternative(event)) { this->power_levels = mpark::get(event); } else if (mpark::holds_alternative(event)) { diff --git a/src/RoomList.cc b/src/RoomList.cc index 13bc0d48..866d28ae 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -199,15 +199,9 @@ RoomList::sync(const std::map> &states, addRoom(settings.at(state.first), state.second, state.first); auto room = rooms_[state.first]; - auto room_state = room->state(); + auto new_avatar = state.second->getAvatar(); - if (room_state) { - auto current_avatar = room_state->getAvatar(); - auto new_avatar = state.second->getAvatar(); - - if (current_avatar != new_avatar && !new_avatar.toString().isEmpty()) - updateAvatar(state.first, new_avatar.toString()); - } + updateAvatar(state.first, new_avatar.toString()); room->setState(state.second); } diff --git a/src/RoomState.cc b/src/RoomState.cc index 244d9e51..de816524 100644 --- a/src/RoomState.cc +++ b/src/RoomState.cc @@ -51,32 +51,41 @@ RoomState::resolveName() } QSettings settings; - auto user_id = settings.value("auth/user_id"); + auto user_id = settings.value("auth/user_id").toString(); // TODO: Display names should be sorted alphabetically. for (const auto membership : memberships) { const auto stateKey = QString::fromStdString(membership.second.state_key); - if (stateKey == user_id) - continue; + if (stateKey == user_id) { + name_ = QString::fromStdString(membership.second.content.display_name); - if (membership.second.content.membership == mtx::events::state::Membership::Join) { - userAvatar_ = stateKey; - auto displayName = - QString::fromStdString(membership.second.content.display_name); - - if (displayName.isEmpty()) + if (name_.isEmpty()) name_ = stateKey; - else - name_ = displayName; + userAvatar_ = stateKey; + + continue; + } + + if (membership.second.content.membership == mtx::events::state::Membership::Join || + membership.second.content.membership == + mtx::events::state::Membership::Invite) { + userAvatar_ = stateKey; + + name_ = QString::fromStdString(membership.second.content.display_name); + + if (name_.isEmpty()) + name_ = stateKey; + + // TODO: pluralization + if (memberships.size() > 2) + name_ = QString("%1 and %2 others") + .arg(name_) + .arg(memberships.size() - 2); break; } } - - // TODO: pluralization - if (memberships.size() > 2) - name_ = QString("%1 and %2 others").arg(name_).arg(memberships.size()); } void