Fix inserting UserListModel items without beginInsertRows()
If an item is added, the corresponding code should be wrapped with beginInsertRows() and endInsertRows(), otherwise proxy or filter models can end up with corrupted internal state. m_members.insert() in refreshMember() should be unnecessary because if pos is not the same as m_members.size(), then it means there's already a member.id() item in the member list.
This commit is contained in:
@@ -146,9 +146,13 @@ bool UserListModel::event(QEvent *event)
|
||||
|
||||
void UserListModel::memberJoined(const Quotient::RoomMember &member)
|
||||
{
|
||||
auto pos = findUserPos(member);
|
||||
beginInsertRows(QModelIndex(), pos, pos);
|
||||
m_members.insert(pos, member.id());
|
||||
if (m_members.contains(member.id())) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int row = m_members.size();
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
m_members.append(member.id());
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@@ -168,8 +172,6 @@ void UserListModel::refreshMember(const Quotient::RoomMember &member, const QLis
|
||||
{
|
||||
auto pos = findUserPos(member);
|
||||
if (pos != m_members.size()) {
|
||||
// The update will have changed the state event so we need to insert the updated member object.
|
||||
m_members.insert(pos, member.id());
|
||||
Q_EMIT dataChanged(index(pos), index(pos), roles);
|
||||
} else {
|
||||
qWarning() << "Trying to access a room member not in the user list";
|
||||
|
||||
Reference in New Issue
Block a user