-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #825(nvrwhere): Create ThreadView to track threads in a room
- Loading branch information
Showing
14 changed files
with
288 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2024 James Graham <[email protected]> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#include "thread.h" | ||
|
||
#include "events/roommessageevent.h" | ||
|
||
using namespace Quotient; | ||
|
||
bool Thread::addEvent(const RoomMessageEvent* event, bool isLatest, bool isLocalUser) | ||
{ | ||
// Note: the root event may not have the thread aggregation in its unsigned on creation | ||
// hence checking the event id. | ||
if (event->threadRootEventId() != threadRootId && event->id() != threadRootId) { | ||
return false; | ||
} | ||
if (isLatest || latestEventId.isEmpty()) { | ||
latestEventId = event->id(); | ||
} | ||
++size; | ||
localUserParticipated |= isLocalUser; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2024 James Graham <[email protected]> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#pragma once | ||
|
||
#include <QString> | ||
|
||
#include "quotient_export.h" | ||
|
||
namespace Quotient { | ||
|
||
class RoomMessageEvent; | ||
|
||
class QUOTIENT_API Thread { | ||
public: | ||
QString threadRootId = {}; | ||
QString latestEventId = {}; | ||
int size = 0; | ||
bool localUserParticipated = {}; | ||
|
||
bool addEvent(const RoomMessageEvent* event, bool isLatest, bool isLocalUser); | ||
}; | ||
|
||
} // namespace Quotient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"content": { | ||
"body": "Thread reply 1 event", | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
"rel_type": "m.thread", | ||
"event_id": "$threadroot:example.org" | ||
} | ||
}, | ||
"event_id": "$thread1:example.org", | ||
"origin_server_ts": 1432735824654, | ||
"room_id": "!test:example.org", | ||
"sender": "@example:example.org", | ||
"type": "m.room.message", | ||
"unsigned": { | ||
"age": 1234 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"content": { | ||
"body": "Thread reply 2 event", | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
"rel_type": "m.thread", | ||
"event_id": "$threadroot:example.org" | ||
} | ||
}, | ||
"event_id": "$thread2:example.org", | ||
"origin_server_ts": 1432735824654, | ||
"room_id": "!test:example.org", | ||
"sender": "@example:example.org", | ||
"type": "m.room.message", | ||
"unsigned": { | ||
"age": 1234 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"content": { | ||
"body": "Thread root event", | ||
"msgtype": "m.text" | ||
}, | ||
"event_id": "$threadroot:example.org", | ||
"origin_server_ts": 1432735824654, | ||
"room_id": "!test:example.org", | ||
"sender": "@example:example.org", | ||
"type": "m.room.message", | ||
"unsigned": { | ||
"age": 1234 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-FileCopyrightText: 2024 James Graham <[email protected]> | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#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(); | ||
const auto rootEvent = loadEventFromFile<RoomMessageEvent>("test-threadroot-event.json"_L1); | ||
|
||
testThread.threadRootId = rootEvent->id(); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, QString()); | ||
QCOMPARE(testThread.size, 0); | ||
QCOMPARE(testThread.localUserParticipated, false); | ||
|
||
testThread.addEvent(rootEvent.get(), true, false); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.size, 1); | ||
QCOMPARE(testThread.localUserParticipated, false); | ||
|
||
const auto replyEvent1 = loadEventFromFile<RoomMessageEvent>("test-thread1-event.json"_L1); | ||
testThread.addEvent(replyEvent1.get(), true, true); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$thread1:example.org"_L1); | ||
QCOMPARE(testThread.size, 2); | ||
QCOMPARE(testThread.localUserParticipated, true); | ||
|
||
const auto replyEvent2 = loadEventFromFile<RoomMessageEvent>("test-thread2-event.json"_L1); | ||
testThread.addEvent(replyEvent2.get(), true, false); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1); | ||
QCOMPARE(testThread.size, 3); | ||
QCOMPARE(testThread.localUserParticipated, true); | ||
} | ||
|
||
void TestThread::historicalThread() | ||
{ | ||
auto testThread = Thread(); | ||
const auto replyEvent2 = loadEventFromFile<RoomMessageEvent>("test-thread2-event.json"_L1); | ||
|
||
testThread.threadRootId = replyEvent2->threadRootEventId(); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, QString()); | ||
QCOMPARE(testThread.size, 0); | ||
QCOMPARE(testThread.localUserParticipated, false); | ||
|
||
testThread.addEvent(replyEvent2.get(), true, false); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1); | ||
QCOMPARE(testThread.size, 1); | ||
QCOMPARE(testThread.localUserParticipated, false); | ||
|
||
const auto replyEvent1 = loadEventFromFile<RoomMessageEvent>("test-thread1-event.json"_L1); | ||
testThread.addEvent(replyEvent1.get(), false, true); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1); | ||
QCOMPARE(testThread.size, 2); | ||
QCOMPARE(testThread.localUserParticipated, true); | ||
|
||
const auto rootEvent = loadEventFromFile<RoomMessageEvent>("test-threadroot-event.json"_L1); | ||
testThread.addEvent(rootEvent.get(), false, true); | ||
QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1); | ||
QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1); | ||
QCOMPARE(testThread.size, 3); | ||
QCOMPARE(testThread.localUserParticipated, true); | ||
} | ||
|
||
QTEST_GUILESS_MAIN(TestThread) | ||
#include "testthread.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.