mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
parent
d6b61fbb14
commit
39a8150fae
3 changed files with 28 additions and 25 deletions
|
@ -111,7 +111,7 @@ RoomState::updateFromEvents(const std::vector<Collection> &collection)
|
|||
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);
|
||||
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)) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
room->setState(state.second);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
break;
|
||||
}
|
||||
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());
|
||||
name_ = QString("%1 and %2 others")
|
||||
.arg(name_)
|
||||
.arg(memberships.size() - 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue