Move pollhandler to ContentProvider
Move `PollHandler` to `ContentProvider`, this also breaks the dependency on `PollHandler` for `NeoChatRoom`
This commit is contained in:
@@ -85,3 +85,25 @@ ThreadModel *ContentProvider::modelForThread(NeoChatRoom *room, const QString &t
|
||||
|
||||
return m_threadModels.object(threadRootId);
|
||||
}
|
||||
|
||||
static PollHandler *emptyPollHandler = new PollHandler;
|
||||
|
||||
PollHandler *ContentProvider::handlerForPoll(NeoChatRoom *room, const QString &eventId)
|
||||
{
|
||||
if (!room || eventId.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto event = room->getEvent(eventId);
|
||||
if (event.first == nullptr || event.second) {
|
||||
return emptyPollHandler;
|
||||
}
|
||||
|
||||
if (!m_pollHandlers.contains(eventId)) {
|
||||
m_pollHandlers.insert(eventId, new PollHandler(room, eventId));
|
||||
}
|
||||
|
||||
return m_pollHandlers.object(eventId);
|
||||
}
|
||||
|
||||
#include "moc_contentprovider.cpp"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "models/messagecontentmodel.h"
|
||||
#include "models/threadmodel.h"
|
||||
#include "neochatroom.h"
|
||||
#include "pollhandler.h"
|
||||
|
||||
/**
|
||||
* @class ContentProvider
|
||||
@@ -70,9 +71,20 @@ public:
|
||||
*/
|
||||
ThreadModel *modelForThread(NeoChatRoom *room, const QString &threadRootId);
|
||||
|
||||
/**
|
||||
* @brief Get a PollHandler object for the given event Id.
|
||||
*
|
||||
* Will return an existing PollHandler if one already exists for the event ID.
|
||||
* A new PollHandler will be created if one doesn't exist.
|
||||
*
|
||||
* @sa PollHandler
|
||||
*/
|
||||
PollHandler *handlerForPoll(NeoChatRoom *room, const QString &eventId);
|
||||
|
||||
private:
|
||||
explicit ContentProvider(QObject *parent = nullptr);
|
||||
|
||||
QCache<QString, MessageContentModel> m_eventContentModels;
|
||||
QCache<QString, ThreadModel> m_threadModels;
|
||||
QCache<QString, PollHandler> m_pollHandlers;
|
||||
};
|
||||
|
||||
@@ -334,7 +334,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
||||
return EventHandler::locationAssetType(event.first);
|
||||
}
|
||||
if (role == PollHandlerRole) {
|
||||
return QVariant::fromValue<PollHandler *>(m_room->poll(m_eventId));
|
||||
return QVariant::fromValue<PollHandler *>(ContentProvider::self().handlerForPoll(m_room, m_eventId));
|
||||
}
|
||||
if (role == ReplyEventIdRole) {
|
||||
if (const auto roomMessageEvent = eventCast<const RoomMessageEvent>(event.first)) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <functional>
|
||||
|
||||
#include "neochatroom.h"
|
||||
#include "pollhandler.h"
|
||||
#include "readmarkermodel.h"
|
||||
#include "threadmodel.h"
|
||||
|
||||
|
||||
@@ -1423,23 +1423,6 @@ bool NeoChatRoom::canEncryptRoom() const
|
||||
return !usesEncryption() && canSendState("m.room.encryption"_L1);
|
||||
}
|
||||
|
||||
static PollHandler *emptyPollHandler = new PollHandler;
|
||||
|
||||
PollHandler *NeoChatRoom::poll(const QString &eventId)
|
||||
{
|
||||
const auto event = getEvent(eventId);
|
||||
if (event.first == nullptr || event.second) {
|
||||
return emptyPollHandler;
|
||||
}
|
||||
|
||||
if (m_polls.contains(eventId)) {
|
||||
return m_polls[eventId];
|
||||
}
|
||||
auto handler = new PollHandler(this, eventId);
|
||||
m_polls.insert(eventId, handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
void NeoChatRoom::postPoll(PollKind::Kind kind, const QString &question, const QList<QString> &answers)
|
||||
{
|
||||
QList<EventContent::Answer> answerStructs;
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#include "enums/messagetype.h"
|
||||
#include "enums/pushrule.h"
|
||||
#include "events/pollevent.h"
|
||||
#include "neochatroommember.h"
|
||||
#include "pollhandler.h"
|
||||
|
||||
namespace Quotient
|
||||
{
|
||||
@@ -488,18 +488,6 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE void editLastMessage();
|
||||
|
||||
/**
|
||||
* @brief Get a PollHandler object for the given event Id.
|
||||
*
|
||||
* Will return an existing PollHandler if one already exists for the event ID.
|
||||
* A new PollHandler will be created if one doesn't exist.
|
||||
*
|
||||
* @note Requires libQuotient 0.7.
|
||||
*
|
||||
* @sa PollHandler
|
||||
*/
|
||||
Q_INVOKABLE PollHandler *poll(const QString &eventId);
|
||||
|
||||
Q_INVOKABLE void postPoll(PollKind::Kind kind, const QString &question, const QList<QString> &answers);
|
||||
|
||||
/**
|
||||
@@ -599,7 +587,6 @@ private:
|
||||
ChatBarCache *m_editCache;
|
||||
ChatBarCache *m_threadCache;
|
||||
|
||||
QCache<QString, PollHandler> m_polls;
|
||||
std::vector<Quotient::event_ptr_tt<Quotient::RoomEvent>> m_extraEvents;
|
||||
void cleanupExtraEventRange(Quotient::RoomEventsRange events);
|
||||
void cleanupExtraEvent(const QString &eventId);
|
||||
|
||||
Reference in New Issue
Block a user