Page MenuHomePhorge

D17.1732272025.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D17.1732272025.diff

diff --git a/src/contents/ui/RoomPage.qml b/src/contents/ui/RoomPage.qml
--- a/src/contents/ui/RoomPage.qml
+++ b/src/contents/ui/RoomPage.qml
@@ -7,6 +7,7 @@
import QtQuick 2.2
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
+import QtQuick.Window 2.15
import org.kde.kirigami 2.13 as Kirigami
import moe.kazv.mxc.kazv 0.0 as MK
@@ -18,6 +19,8 @@
id: roomPage
property string roomId: ''
property var room: sdkVars.roomList.room(roomId)
+ property var roomTimeline: room.timeline()
+ property var lastReceiptableEventId: getLastReceiptableEventId(roomTimeline, roomTimeline.count)
signal mentionUserRequested(string userId)
@@ -91,7 +94,7 @@
}
RoomTimelineView {
- timeline: room.timeline()
+ timeline: roomPage.roomTimeline
}
onRoomChanged: {
@@ -164,4 +167,44 @@
sendMessageBox.mentionUser(userId);
sendMessageBox.focusInput();
}
+
+ function getLastReceiptableEventId(timeline, timelineCount) {
+ for (let i = 0; i < timelineCount; ++i) {
+ const event = timeline.at(i);
+ if (!event.isLocalEcho && event.sender !== matrixSdk.userId) {
+ return event.eventId;
+ }
+ }
+ }
+
+ onLastReceiptableEventIdChanged: maybePostReadReceipt()
+
+ Window.onActiveChanged: maybePostReadReceipt()
+
+ onVisibleChanged: maybePostReadReceipt()
+
+ function maybePostReadReceipt() {
+ if (!Window.active || !roomPage.visible) {
+ return;
+ }
+
+ const eventId = roomPage.lastReceiptableEventId;
+ if (!eventId) {
+ return;
+ }
+
+ const event = roomPage.room.messageById(eventId);
+ const readers = event.readers();
+ let readByMe = false;
+ for (let i = 0; i < readers.count; ++i) {
+ const reader = readers.at(i);
+ if (reader.userId === matrixSdk.userId) {
+ readByMe = true;
+ break;
+ }
+ }
+ if (!readByMe) {
+ roomPage.room.postReadReceipt(eventId);
+ }
+ }
}
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -125,6 +125,8 @@
Q_INVOKABLE MatrixPromise *inviteUser(const QString &userId) const;
+ Q_INVOKABLE MatrixPromise *postReadReceipt(const QString &eventId) const;
+
Q_SIGNALS:
void powerLevelsChanged();
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -449,3 +449,8 @@
{
return new MatrixPromise(m_room.invite(userId.toStdString()));
}
+
+MatrixPromise *MatrixRoom::postReadReceipt(const QString &eventId) const
+{
+ return new MatrixPromise(m_room.postReceipt(eventId.toStdString()));
+}
diff --git a/src/tests/quick-tests/tst_RoomPage.qml b/src/tests/quick-tests/tst_RoomPage.qml
--- a/src/tests/quick-tests/tst_RoomPage.qml
+++ b/src/tests/quick-tests/tst_RoomPage.qml
@@ -19,6 +19,30 @@
width: 800
height: 600
+ property var roomTimeline: QtObject {
+ property var count: 5
+ function at(i) {
+ if (i < 2) {
+ return {
+ isLocalEcho: true,
+ };
+ }
+ if (i < 3) {
+ return {
+ isLocalEcho: false,
+ sender: '@foo:example.org',
+ eventId: `$event${i}`,
+ };
+ }
+
+ return {
+ isLocalEcho: false,
+ sender: '@bar:example.org',
+ eventId: `$event${i}`,
+ };
+ }
+ }
+
property var roomInvite: Helpers.factory.room({
membership: MK.MatrixRoom.Invite,
})
@@ -32,7 +56,9 @@
})
property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var userId: '@foo:example.org'
+ }
property var sdkVars: ({})
ColumnLayout {
@@ -74,5 +100,9 @@
verify(sendMessageBox);
verify(!sendMessageBox.enabled);
}
+
+ function test_receiptableEventId() {
+ verify(pageJoin.getLastReceiptableEventId(item.roomTimeline, item.roomTimeline.count) === '$event3');
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 2:40 AM (16 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38791
Default Alt Text
D17.1732272025.diff (3 KB)

Event Timeline