Move the storage of thread models to the room
This commit is contained in:
@@ -425,11 +425,6 @@ void MessageModel::createEventObjects(const Quotient::RoomEvent *event, bool isP
|
|||||||
senderId = m_room->localMember().id();
|
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
|
// ReadMarkerModel handles updates to add and remove markers, we only need to
|
||||||
// handle adding and removing whole models here.
|
// handle adding and removing whole models here.
|
||||||
if (m_readMarkerModels.contains(eventId)) {
|
if (m_readMarkerModels.contains(eventId)) {
|
||||||
@@ -518,7 +513,7 @@ bool MessageModel::event(QEvent *event)
|
|||||||
|
|
||||||
ThreadModel *MessageModel::threadModelForRootId(const QString &threadRootId) const
|
ThreadModel *MessageModel::threadModelForRootId(const QString &threadRootId) const
|
||||||
{
|
{
|
||||||
return m_threadModels[threadRootId].data();
|
return m_room->modelForThread(threadRootId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_messagemodel.cpp"
|
#include "moc_messagemodel.cpp"
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ private:
|
|||||||
bool movingEvent = false;
|
bool movingEvent = false;
|
||||||
|
|
||||||
QMap<QString, QSharedPointer<ReadMarkerModel>> m_readMarkerModels;
|
QMap<QString, QSharedPointer<ReadMarkerModel>> m_readMarkerModels;
|
||||||
QMap<QString, QSharedPointer<ThreadModel>> m_threadModels;
|
|
||||||
QMap<QString, QSharedPointer<ReactionModel>> m_reactionModels;
|
QMap<QString, QSharedPointer<ReactionModel>> m_reactionModels;
|
||||||
|
|
||||||
void createEventObjects(const Quotient::RoomEvent *event, bool isPending = false);
|
void createEventObjects(const Quotient::RoomEvent *event, bool isPending = false);
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ void NeoChatRoom::setVisible(bool visible)
|
|||||||
if (!visible) {
|
if (!visible) {
|
||||||
m_memberObjects.clear();
|
m_memberObjects.clear();
|
||||||
m_eventContentModels.clear();
|
m_eventContentModels.clear();
|
||||||
|
m_threadModels.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1797,4 +1798,17 @@ MessageContentModel *NeoChatRoom::contentModelForEvent(const QString &evtOrTxnId
|
|||||||
return nullptr;
|
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"
|
#include "moc_neochatroom.cpp"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "enums/messagetype.h"
|
#include "enums/messagetype.h"
|
||||||
#include "enums/pushrule.h"
|
#include "enums/pushrule.h"
|
||||||
#include "models/messagecontentmodel.h"
|
#include "models/messagecontentmodel.h"
|
||||||
|
#include "models/threadmodel.h"
|
||||||
#include "neochatroommember.h"
|
#include "neochatroommember.h"
|
||||||
#include "pollhandler.h"
|
#include "pollhandler.h"
|
||||||
|
|
||||||
@@ -598,6 +599,14 @@ public:
|
|||||||
|
|
||||||
MessageContentModel *contentModelForEvent(const QString &evtOrTxnId);
|
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:
|
private:
|
||||||
bool m_visible = false;
|
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<NeochatRoomMember>> m_memberObjects;
|
||||||
std::unordered_map<QString, std::unique_ptr<MessageContentModel>> m_eventContentModels;
|
std::unordered_map<QString, std::unique_ptr<MessageContentModel>> m_eventContentModels;
|
||||||
|
std::unordered_map<QString, std::unique_ptr<ThreadModel>> m_threadModels;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updatePushNotificationState(QString type);
|
void updatePushNotificationState(QString type);
|
||||||
|
|||||||
Reference in New Issue
Block a user