Update room name & avatar on new rooms

fixes #253
pull/1/head
Konstantinos Sideris 7 years ago
parent d6b61fbb14
commit 39a8150fae
  1. 2
      include/RoomState.h
  2. 6
      src/RoomList.cc
  3. 33
      src/RoomState.cc

@ -111,7 +111,7 @@ RoomState::updateFromEvents(const std::vector<Collection> &collection)
this->name = mpark::get<Name>(event); this->name = mpark::get<Name>(event);
} else if (mpark::holds_alternative<Member>(event)) { } else if (mpark::holds_alternative<Member>(event)) {
auto membership = mpark::get<Member>(event); auto membership = mpark::get<Member>(event);
this->memberships.emplace(membership.state_key, membership); memberships[membership.state_key] = membership;
} else if (mpark::holds_alternative<PowerLevels>(event)) { } else if (mpark::holds_alternative<PowerLevels>(event)) {
this->power_levels = mpark::get<PowerLevels>(event); this->power_levels = mpark::get<PowerLevels>(event);
} else if (mpark::holds_alternative<Topic>(event)) { } else if (mpark::holds_alternative<Topic>(event)) {

@ -199,15 +199,9 @@ RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &states,
addRoom(settings.at(state.first), state.second, state.first); addRoom(settings.at(state.first), state.second, state.first);
auto room = rooms_[state.first]; auto room = rooms_[state.first];
auto room_state = room->state();
if (room_state) {
auto current_avatar = room_state->getAvatar();
auto new_avatar = state.second->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); room->setState(state.second);
} }

@ -51,32 +51,41 @@ RoomState::resolveName()
} }
QSettings settings; 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. // TODO: Display names should be sorted alphabetically.
for (const auto membership : memberships) { for (const auto membership : memberships) {
const auto stateKey = QString::fromStdString(membership.second.state_key); const auto stateKey = QString::fromStdString(membership.second.state_key);
if (stateKey == user_id) if (stateKey == user_id) {
name_ = QString::fromStdString(membership.second.content.display_name);
if (name_.isEmpty())
name_ = stateKey;
userAvatar_ = stateKey;
continue; continue;
}
if (membership.second.content.membership == mtx::events::state::Membership::Join) { if (membership.second.content.membership == mtx::events::state::Membership::Join ||
membership.second.content.membership ==
mtx::events::state::Membership::Invite) {
userAvatar_ = stateKey; userAvatar_ = stateKey;
auto displayName =
QString::fromStdString(membership.second.content.display_name);
if (displayName.isEmpty()) name_ = QString::fromStdString(membership.second.content.display_name);
if (name_.isEmpty())
name_ = stateKey; name_ = stateKey;
else
name_ = displayName;
// TODO: pluralization
if (memberships.size() > 2)
name_ = QString("%1 and %2 others")
.arg(name_)
.arg(memberships.size() - 2);
break; break;
} }
} }
// TODO: pluralization
if (memberships.size() > 2)
name_ = QString("%1 and %2 others").arg(name_).arg(memberships.size());
} }
void void

Loading…
Cancel
Save