Refactor PollHandler

Refactor PollHandler to make it more reliable. This ended up with much more code than I expected as the original intent was just to stop a crash when switching rooms.
- Using a event string was flaky, changing to using an event reference is more reliable.
- Since we're only creating them from NeoChatRoom there is no need to to be able to set properties from QML so only read properties.
- Pass from the MessageEventModel rather than an invokable method.
- Create a basic test suite
- Create properties in PollHandler to remove the need to use content in PollDelegate, this means content is no longer a required role.
This commit is contained in:
James Graham
2024-01-02 21:22:08 +00:00
parent 7ad362225f
commit 356e8eefe0
10 changed files with 259 additions and 116 deletions

View File

@@ -1725,15 +1725,26 @@ bool NeoChatRoom::canEncryptRoom() const
return !usesEncryption() && canSendState("m.room.encryption"_ls);
}
PollHandler *NeoChatRoom::poll(const QString &eventId)
static PollHandler *emptyPollHandler = new PollHandler;
PollHandler *NeoChatRoom::poll(const QString &eventId) const
{
if (auto pollHandler = m_polls[eventId]) {
return pollHandler;
}
return emptyPollHandler;
}
void NeoChatRoom::createPollHandler(const Quotient::PollStartEvent *event)
{
if (event == nullptr) {
return;
}
auto eventId = event->id();
if (!m_polls.contains(eventId)) {
auto handler = new PollHandler(this);
handler->setRoom(this);
handler->setPollStartEventId(eventId);
auto handler = new PollHandler(this, event);
m_polls.insert(eventId, handler);
}
return m_polls[eventId];
}
bool NeoChatRoom::downloadTempFile(const QString &eventId)