Page MenuHomePhorge

D342.1786193015.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D342.1786193015.diff

diff --git a/src/matrix-room-timeline.cpp b/src/matrix-room-timeline.cpp
--- a/src/matrix-room-timeline.cpp
+++ b/src/matrix-room-timeline.cpp
@@ -64,7 +64,13 @@
.map([index](const auto &tlEventIds, const auto &messagesMap, const auto &localEchoes, const auto &count) -> std::variant<Kazv::Event, Kazv::LocalEchoDesc, std::string> {
auto rIndex = count - index - 1;
if (static_cast<unsigned int>(rIndex) < tlEventIds.size()) {
- return messagesMap[tlEventIds[rIndex]];
+ auto eventId = tlEventIds[rIndex];
+ // For some timelines like pinned events, the message may not be available
+ if (messagesMap.count(eventId)) {
+ return messagesMap[eventId];
+ } else {
+ return eventId;
+ }
} else {
auto remainingIndex = rIndex - tlEventIds.size();
if (remainingIndex < localEchoes.size()) {
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -23,6 +23,7 @@
matrix-sdk-sessions-test.cpp
matrix-promise-test.cpp
matrix-room-timeline-test.cpp
+ matrix-room-pinned-events-timeline-test.cpp
matrix-room-member-list-model-test.cpp
matrix-room-list-test.cpp
matrix-room-state-test.cpp
diff --git a/src/tests/matrix-room-pinned-events-timeline-test.cpp b/src/tests/matrix-room-pinned-events-timeline-test.cpp
new file mode 100644
--- /dev/null
+++ b/src/tests/matrix-room-pinned-events-timeline-test.cpp
@@ -0,0 +1,60 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <kazv-defs.hpp>
+#include "test-model.hpp"
+#include "test-utils.hpp"
+#include <matrix-event.hpp>
+#include <matrix-room.hpp>
+#include <matrix-room-pinned-events-timeline.hpp>
+#include <matrix-room-list.hpp>
+#include <matrix-session.hpp>
+#include <factory.hpp>
+#include <QtTest>
+
+using namespace Qt::Literals::StringLiterals;
+using namespace Kazv;
+using namespace Kazv::Factory;
+
+class MatrixRoomPinnedEventsTimelineTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testUnavailable();
+};
+
+void MatrixRoomPinnedEventsTimelineTest::testUnavailable()
+{
+ auto r = makeRoom(withRoomTimeline({
+ makeEvent(withEventId("$1")),
+ makeEvent(withEventId("$2")),
+ }) | withRoomState({
+ makeEvent(withEventType("m.room.pinned_events")
+ | withEventContent(json::object({
+ {"pinned", json::array({"$1", "$3"})},
+ }))
+ | withStateKey(""))
+ }));
+ auto model = SdkModel{makeClient(withRoom(r))};
+ SessionSetup s(model);
+ auto roomList = toUniquePtr(s.session.roomList());
+ auto room = toUniquePtr(roomList->room(QString::fromStdString(r.roomId)));
+ auto timeline = toUniquePtr(room->pinnedEventsTimeline());
+ QCOMPARE(timeline->count(), 2);
+
+ auto e1 = toUniquePtr(timeline->at(1));
+ QCOMPARE(e1->eventId(), u"$1"_s);
+ QVERIFY(e1->isAvailable());
+
+ auto e0 = toUniquePtr(timeline->at(0));
+ QCOMPARE(e0->eventId(), u"$3"_s);
+ QVERIFY(!e0->isAvailable());
+}
+
+QTEST_MAIN(MatrixRoomPinnedEventsTimelineTest)
+
+#include "matrix-room-pinned-events-timeline-test.moc"

File Metadata

Mime Type
text/plain
Expires
Sat, Aug 8, 5:43 AM (16 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1718985
Default Alt Text
D342.1786193015.diff (3 KB)

Event Timeline