Skip to content

Commit

Permalink
Further comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nvrWhere committed Dec 4, 2024
1 parent acf7b60 commit cfe6e4f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
8 changes: 3 additions & 5 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "events/typingevent.h"
#include "jobs/downloadfilejob.h"
#include "jobs/mediathumbnailjob.h"
#include <Quotient/events/roommessageevent.h>

// NB: since Qt 6, moc_room.cpp needs User fully defined
#include "moc_room.cpp" // NOLINT(bugprone-suspicious-include)
Expand Down Expand Up @@ -1780,11 +1779,10 @@ void Room::Private::updateThread(const RoomEvent* event)
auto& thread = threads[rme->threadRootEventId()];
if (thread.threadRootId.isEmpty()) {
thread.threadRootId = rme->threadRootEventId();
const auto threadRootIndex = eventsIndex.constFind(rme->threadRootEventId());
// If we can't find the root we assume it's a historical event and will be loaded later.
if (threadRootIndex != eventsIndex.cend()) {
const auto rootEvent = timeline[Timeline::size_type(*threadRootIndex - q->minTimelineIndex())].viewAs<RoomMessageEvent>();
thread.addEvent(rootEvent, true, rootEvent->senderId() == connection->userId());
if (auto rootIt = q->findInTimeline(thread.threadRootId); rootIt != historyEdge()) {
thread.addEvent(rootIt->viewAs<RoomMessageEvent>(), true,
(*rootIt)->senderId() == connection->userId());
}
}

Expand Down
15 changes: 13 additions & 2 deletions autotests/testthread.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <[email protected]>
// SPDX-FileCopyrightText: 2024 James Graham <[email protected]>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "testthread.h"
#include <QTest>

#include <Quotient/events/roommessageevent.h>
#include <Quotient/thread.h>

#include "testutils.h"

using namespace Quotient;

class TestThread : public QObject
{
Q_OBJECT

private Q_SLOTS:
void newThread();
void historicalThread();
};

void TestThread::newThread()
{
auto testThread = Thread();
Expand Down Expand Up @@ -75,3 +85,4 @@ void TestThread::historicalThread()
}

QTEST_GUILESS_MAIN(TestThread)
#include "testthread.moc"
14 changes: 0 additions & 14 deletions autotests/testthread.h

This file was deleted.

2 changes: 1 addition & 1 deletion autotests/testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ inline event_ptr_tt<EventT> loadEventFromFile(const QString &eventFileName)
{
if (!eventFileName.isEmpty()) {
QFile testEventFile;
testEventFile.setFileName(QLatin1String(DATA_DIR) + u'/' + eventFileName);
testEventFile.setFileName(QLatin1StringView(DATA_DIR) + u'/' + eventFileName);
testEventFile.open(QIODevice::ReadOnly);
return loadEvent<EventT>(QJsonDocument::fromJson(testEventFile.readAll()).object());
}
Expand Down
14 changes: 6 additions & 8 deletions quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <QtNetwork/QNetworkReply>

#include <iostream>
#include <stdexcept>

using namespace Quotient;
using std::clog, std::endl;
Expand Down Expand Up @@ -882,11 +881,11 @@ TEST_IMPL(thread)
connect(targetRoom, &Room::pendingEventAboutToMerge, this, [this, thisTest, rootTxnId](Quotient::RoomEvent* rootEvt) {
if (rootEvt->transactionId() == rootTxnId) {
const auto relation = EventRelation::replyInThread(rootEvt->id(), true, rootEvt->id());
auto replyTxnId = targetRoom->post<RoomMessageEvent>(u"Thread reply 1"_s, RoomMessageEvent::MsgType::Text, nullptr, relation)->transactionId();
connect(targetRoom, &Room::pendingEventAboutToMerge, this, [this, thisTest, replyTxnId](Quotient::RoomEvent* replyEvt) {
if (replyEvt->transactionId() == replyTxnId) {
connect(targetRoom, &Room::pendingEventMerged, this, [this, thisTest, replyEvt]() {
replyEvt->switchOnType(
targetRoom->post<Quotient::RoomMessageEvent>(u"Thread reply 1"_s, Quotient::RoomMessageEvent::MsgType::Text, nullptr, relation)
.whenMerged()
.then([this, thisTest](const RoomEvent& replyEvt) {
connect(targetRoom, &Room::pendingEventMerged, this, [this, thisTest, &replyEvt]() {
replyEvt.switchOnType(
[&](const RoomMessageEvent& rmReplyEvt) {
const auto thread = targetRoom->threads()[rmReplyEvt.threadRootEventId()];
FINISH_TEST(thread.threadRootId == rmReplyEvt.threadRootEventId() &&
Expand All @@ -897,8 +896,7 @@ TEST_IMPL(thread)
[this, thisTest](const RoomEvent&) { FAIL_TEST(); }
);
});
}
});
});
}
});

Expand Down

0 comments on commit cfe6e4f

Please sign in to comment.