Update room name & avatar on new rooms

fixes #253
This commit is contained in:
Konstantinos Sideris 2018-03-12 00:15:06 +02:00
parent d6b61fbb14
commit 39a8150fae
3 changed files with 28 additions and 25 deletions

View file

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

View file

@ -199,15 +199,9 @@ RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &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);
}

View file

@ -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