Remove the relationEventContentModel function from ChatBarCache
Remove the relationEventContentModel function from ChatBarCache as ContentProvider makes it unneeded. This means turning ContentProvider into a QML singleton.
This commit is contained in:
@@ -374,7 +374,7 @@ QQC2.Control {
|
||||
id: replyComponent
|
||||
replyEventId: _private.chatBarCache.replyId
|
||||
replyAuthor: _private.chatBarCache.relationAuthor
|
||||
replyContentModel: _private.chatBarCache.relationEventContentModel
|
||||
replyContentModel: ContentProvider.contentModelForEvent(root.currentRoom, _private.chatBarCache.replyId, true)
|
||||
Message.maxContentWidth: replyLoader.item.width
|
||||
}
|
||||
QQC2.Button {
|
||||
|
||||
@@ -162,24 +162,6 @@ QString ChatBarCache::relationMessage() const
|
||||
return {};
|
||||
}
|
||||
|
||||
MessageContentModel *ChatBarCache::relationEventContentModel()
|
||||
{
|
||||
if (parent() == nullptr) {
|
||||
qWarning() << "ChatBarCache created with no parent, a NeoChatRoom must be set as the parent on creation.";
|
||||
return nullptr;
|
||||
}
|
||||
if (m_relationId.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto room = dynamic_cast<NeoChatRoom *>(parent());
|
||||
if (room == nullptr) {
|
||||
qWarning() << "ChatBarCache created with incorrect parent, a NeoChatRoom must be set as the parent on creation.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ContentProvider::self().contentModelForEvent(room, m_relationId);
|
||||
}
|
||||
|
||||
bool ChatBarCache::isThreaded() const
|
||||
{
|
||||
return !m_threadId.isEmpty();
|
||||
|
||||
@@ -111,13 +111,6 @@ class ChatBarCache : public QObject
|
||||
*/
|
||||
Q_PROPERTY(QString relationMessage READ relationMessage NOTIFY relationIdChanged)
|
||||
|
||||
/**
|
||||
* @brief The MessageContentModel for the related message.
|
||||
*
|
||||
* Will be nullptr if no related message.
|
||||
*/
|
||||
Q_PROPERTY(MessageContentModel *relationEventContentModel READ relationEventContentModel NOTIFY relationIdChanged)
|
||||
|
||||
/**
|
||||
* @brief Whether the chat bar is replying in a thread.
|
||||
*/
|
||||
@@ -167,7 +160,6 @@ public:
|
||||
Quotient::RoomMember relationAuthor() const;
|
||||
|
||||
QString relationMessage() const;
|
||||
MessageContentModel *relationEventContentModel();
|
||||
|
||||
bool isThreaded() const;
|
||||
QString threadId() const;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include "contentprovider.h"
|
||||
|
||||
ContentProvider::ContentProvider()
|
||||
ContentProvider::ContentProvider(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QCache>
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "models/messagecontentmodel.h"
|
||||
#include "models/threadmodel.h"
|
||||
@@ -14,13 +16,22 @@
|
||||
*
|
||||
* Store and retrieve models for message content.
|
||||
*/
|
||||
class ContentProvider
|
||||
class ContentProvider : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
public:
|
||||
/**
|
||||
* Get the global instance of ContentProvider.
|
||||
*/
|
||||
static ContentProvider &self();
|
||||
static ContentProvider *create(QQmlEngine *engine, QJSEngine *)
|
||||
{
|
||||
engine->setObjectOwnership(&self(), QQmlEngine::CppOwnership);
|
||||
return &self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the content model for the given event ID.
|
||||
@@ -34,7 +45,7 @@ public:
|
||||
*
|
||||
* @warning Do NOT use for pending events as this function has no way to differentiate.
|
||||
*/
|
||||
MessageContentModel *contentModelForEvent(NeoChatRoom *room, const QString &evtOrTxnId, bool isReply = false);
|
||||
Q_INVOKABLE MessageContentModel *contentModelForEvent(NeoChatRoom *room, const QString &evtOrTxnId, bool isReply = false);
|
||||
|
||||
/**
|
||||
* @brief Returns the content model for the given event.
|
||||
@@ -60,7 +71,7 @@ public:
|
||||
ThreadModel *modelForThread(NeoChatRoom *room, const QString &threadRootId);
|
||||
|
||||
private:
|
||||
ContentProvider();
|
||||
explicit ContentProvider(QObject *parent = nullptr);
|
||||
|
||||
QCache<QString, MessageContentModel> m_eventContentModels;
|
||||
QCache<QString, ThreadModel> m_threadModels;
|
||||
|
||||
@@ -219,7 +219,7 @@ QQC2.Control {
|
||||
id: replyComponent
|
||||
replyEventId: root.chatBarCache.replyId
|
||||
replyAuthor: root.chatBarCache.relationAuthor
|
||||
replyContentModel: root.chatBarCache.relationEventContentModel
|
||||
replyContentModel: ContentProvider.contentModelForEvent(root.Message.room, root.chatBarCache.replyId, true)
|
||||
Message.maxContentWidth: paneLoader.item.width
|
||||
}
|
||||
QQC2.Button {
|
||||
|
||||
Reference in New Issue
Block a user