Only save eventId in MessageContentModel

Turns out trying to manage pointers in the model is a bad idea so only save eventId in MessageContentModel, events pointers will now only be obtained temporarily then discarded to avoid both creating additional copies of the event in the model and potential sources of crashes.

This also creates a basic unit test that we can add to going forward.
This commit is contained in:
James Graham
2024-09-15 08:28:46 +00:00
parent e0c3b7f808
commit ec6a8dd028
8 changed files with 299 additions and 210 deletions

View File

@@ -80,7 +80,7 @@ void ThreadModel::fetchMore(const QModelIndex &parent)
const auto room = dynamic_cast<NeoChatRoom *>(QObject::parent());
auto newEvents = m_currentJob->chunk();
for (auto &event : newEvents) {
m_contentModels.push_back(new MessageContentModel(room, event.get()));
m_contentModels.push_back(new MessageContentModel(room, event->id()));
}
addModels();
@@ -103,7 +103,7 @@ void ThreadModel::fetchMore(const QModelIndex &parent)
void ThreadModel::addNewEvent(const Quotient::RoomEvent *event)
{
const auto room = dynamic_cast<NeoChatRoom *>(QObject::parent());
m_contentModels.push_front(new MessageContentModel(room, event));
m_contentModels.push_front(new MessageContentModel(room, event->id()));
}
void ThreadModel::addModels()