Move the storage of thread models to the room

This commit is contained in:
James Graham
2025-01-11 12:14:31 +00:00
parent 37de1ec583
commit ae7bfa5bcb
4 changed files with 25 additions and 7 deletions

View File

@@ -425,11 +425,6 @@ void MessageModel::createEventObjects(const Quotient::RoomEvent *event, bool isP
senderId = m_room->localMember().id();
}
const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event);
if (roomMessageEvent && roomMessageEvent->isThreaded() && !m_threadModels.contains(roomMessageEvent->threadRootEventId())) {
m_threadModels[roomMessageEvent->threadRootEventId()] = QSharedPointer<ThreadModel>(new ThreadModel(roomMessageEvent->threadRootEventId(), m_room));
}
// ReadMarkerModel handles updates to add and remove markers, we only need to
// handle adding and removing whole models here.
if (m_readMarkerModels.contains(eventId)) {
@@ -518,7 +513,7 @@ bool MessageModel::event(QEvent *event)
ThreadModel *MessageModel::threadModelForRootId(const QString &threadRootId) const
{
return m_threadModels[threadRootId].data();
return m_room->modelForThread(threadRootId);
}
#include "moc_messagemodel.cpp"

View File

@@ -153,7 +153,6 @@ private:
bool movingEvent = false;
QMap<QString, QSharedPointer<ReadMarkerModel>> m_readMarkerModels;
QMap<QString, QSharedPointer<ThreadModel>> m_threadModels;
QMap<QString, QSharedPointer<ReactionModel>> m_reactionModels;
void createEventObjects(const Quotient::RoomEvent *event, bool isPending = false);

View File

@@ -174,6 +174,7 @@ void NeoChatRoom::setVisible(bool visible)
if (!visible) {
m_memberObjects.clear();
m_eventContentModels.clear();
m_threadModels.clear();
}
}
@@ -1797,4 +1798,17 @@ MessageContentModel *NeoChatRoom::contentModelForEvent(const QString &evtOrTxnId
return nullptr;
}
ThreadModel *NeoChatRoom::modelForThread(const QString &threadRootId)
{
if (threadRootId.isEmpty()) {
return nullptr;
}
if (!m_threadModels.contains(threadRootId)) {
return m_threadModels.emplace(threadRootId, std::make_unique<ThreadModel>(threadRootId, this)).first->second.get();
}
return m_threadModels[threadRootId].get();
}
#include "moc_neochatroom.cpp"

View File

@@ -15,6 +15,7 @@
#include "enums/messagetype.h"
#include "enums/pushrule.h"
#include "models/messagecontentmodel.h"
#include "models/threadmodel.h"
#include "neochatroommember.h"
#include "pollhandler.h"
@@ -598,6 +599,14 @@ public:
MessageContentModel *contentModelForEvent(const QString &evtOrTxnId);
/**
* @brief Returns the thread model for the given thread root event ID.
*
* A model is created is one doesn't exist. Will return nullptr if threadRootId
* is empty.
*/
ThreadModel *modelForThread(const QString &threadRootId);
private:
bool m_visible = false;
@@ -631,6 +640,7 @@ private:
std::unordered_map<QString, std::unique_ptr<NeochatRoomMember>> m_memberObjects;
std::unordered_map<QString, std::unique_ptr<MessageContentModel>> m_eventContentModels;
std::unordered_map<QString, std::unique_ptr<ThreadModel>> m_threadModels;
private Q_SLOTS:
void updatePushNotificationState(QString type);