Store NeochatRoomMember objects in the room

Store NeochatRoomMember objects in the room so we don't duplicate them unnecessarily. This also adds a visible property for a room which is set true when shown by MessageEventModel and false when not, triggering the deletion of member objects. This mechanism will be used for other object types in the future.
This commit is contained in:
James Graham
2025-01-05 11:06:42 +00:00
parent 3dbe605de8
commit c21e9f2114
5 changed files with 74 additions and 18 deletions

View File

@@ -54,6 +54,9 @@ void MessageModel::setRoom(NeoChatRoom *room)
beginResetModel();
m_room = room;
if (m_room != nullptr) {
m_room->setVisible(true);
}
Q_EMIT roomChanged();
endResetModel();
}
@@ -493,12 +496,17 @@ void MessageModel::createEventObjects(const Quotient::RoomEvent *event, bool isP
void MessageModel::clearModel()
{
if (m_room) {
const auto oldRoom = m_room;
// 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_room->disconnect(this);
m_room = nullptr;
endResetModel();
// Because we don't want any of the object deleted before the model is cleared.
oldRoom->setVisible(false);
}
// Don't clear the member objects until the model has been fully reset and all