mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
parent
d6b61fbb14
commit
39a8150fae
3 changed files with 28 additions and 25 deletions
|
@ -110,8 +110,8 @@ RoomState::updateFromEvents(const std::vector<Collection> &collection)
|
||||||
} else if (mpark::holds_alternative<Name>(event)) {
|
} else if (mpark::holds_alternative<Name>(event)) {
|
||||||
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();
|
auto new_avatar = state.second->getAvatar();
|
||||||
|
|
||||||
if (room_state) {
|
updateAvatar(state.first, new_avatar.toString());
|
||||||
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);
|
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) {
|
||||||
continue;
|
name_ = QString::fromStdString(membership.second.content.display_name);
|
||||||
|
|
||||||
if (membership.second.content.membership == mtx::events::state::Membership::Join) {
|
if (name_.isEmpty())
|
||||||
userAvatar_ = stateKey;
|
|
||||||
auto displayName =
|
|
||||||
QString::fromStdString(membership.second.content.display_name);
|
|
||||||
|
|
||||||
if (displayName.isEmpty())
|
|
||||||
name_ = stateKey;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: pluralization
|
|
||||||
if (memberships.size() > 2)
|
|
||||||
name_ = QString("%1 and %2 others").arg(name_).arg(memberships.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue