When switching rooms first set the room to nullptr to clear any objects in MessageEventModel and UserListModel

This commit is contained in:
James Graham
2024-06-30 10:15:34 +01:00
parent b3bd6ee176
commit 6a100bfbab
2 changed files with 12 additions and 2 deletions

View File

@@ -84,12 +84,16 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
return; return;
} }
beginResetModel();
if (m_currentRoom) { if (m_currentRoom) {
// HACK: Reset the model to a null room first to make sure QML dismantles
// last room's objects before the room is actually changed
beginResetModel();
m_currentRoom->disconnect(this); m_currentRoom->disconnect(this);
m_reactionModels.clear(); m_currentRoom = nullptr;
endResetModel();
} }
beginResetModel();
m_currentRoom = room; m_currentRoom = room;
Q_EMIT roomChanged(); Q_EMIT roomChanged();
if (room) { if (room) {

View File

@@ -25,9 +25,15 @@ void UserListModel::setRoom(NeoChatRoom *room)
} }
if (m_currentRoom) { if (m_currentRoom) {
// HACK: Reset the model to a null room first to make sure QML dismantles
// last room's objects before the room is actually changed
beginResetModel();
m_currentRoom->disconnect(this); m_currentRoom->disconnect(this);
m_currentRoom->connection()->disconnect(this); m_currentRoom->connection()->disconnect(this);
m_currentRoom = nullptr;
endResetModel();
} }
m_currentRoom = room; m_currentRoom = room;
if (m_currentRoom) { if (m_currentRoom) {