Update user sort
Update the user model so it also sorts by power level and update how we initialize the model to improve performance. The following is also changed: - Store a single `UserListModel` in `RoomManager` and use it for everything, this means we don't create extra models (incluiding the long initialisation for each in big rooms) - By using the single model once it has loaded the users of the new room opening and closing the draw now happens instantly (previously the model would have to be loaded every time the drawer was opened). - To stop the initial loading and room change of Neochat slowing down (as the `UserListModel` would be loaded before the `TimelineView` is shown) the initialisation of the model is delayed until the `TimelineView` has loaded. This prioritises showing some messages in the timeline over populating the model so in large rooms the user list will initially be blank, but this keeps the initial load snappier.
This commit is contained in:
@@ -33,6 +33,7 @@ void UserListModel::setRoom(NeoChatRoom *room)
|
||||
m_currentRoom->disconnect(this);
|
||||
m_currentRoom->connection()->disconnect(this);
|
||||
m_currentRoom = nullptr;
|
||||
m_members.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ void UserListModel::setRoom(NeoChatRoom *room)
|
||||
});
|
||||
}
|
||||
|
||||
refreshAllMembers();
|
||||
m_active = false;
|
||||
Q_EMIT roomChanged();
|
||||
}
|
||||
|
||||
@@ -169,7 +170,6 @@ void UserListModel::refreshMember(const Quotient::RoomMember &member, const QLis
|
||||
void UserListModel::refreshAllMembers()
|
||||
{
|
||||
beginResetModel();
|
||||
m_members.clear();
|
||||
|
||||
if (m_currentRoom != nullptr) {
|
||||
m_members = m_currentRoom->joinedMemberIds();
|
||||
@@ -179,8 +179,17 @@ void UserListModel::refreshAllMembers()
|
||||
MemberSorter sorter(m_currentRoom);
|
||||
#endif
|
||||
std::sort(m_members.begin(), m_members.end(), [&sorter, this](const auto &left, const auto &right) {
|
||||
const auto leftPl = m_currentRoom->getUserPowerLevel(left);
|
||||
const auto rightPl = m_currentRoom->getUserPowerLevel(right);
|
||||
if (leftPl > rightPl) {
|
||||
return true;
|
||||
} else if (rightPl > leftPl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sorter(m_currentRoom->member(left), m_currentRoom->member(right));
|
||||
});
|
||||
|
||||
}
|
||||
endResetModel();
|
||||
Q_EMIT usersRefreshed();
|
||||
@@ -216,4 +225,14 @@ QHash<int, QByteArray> UserListModel::roleNames() const
|
||||
return roles;
|
||||
}
|
||||
|
||||
void UserListModel::activate()
|
||||
{
|
||||
if (m_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_active = true;
|
||||
refreshAllMembers();
|
||||
}
|
||||
|
||||
#include "moc_userlistmodel.cpp"
|
||||
|
||||
Reference in New Issue
Block a user