From 9e3b66f4aa7f9394d3062fdd793ae010ae1f66f0 Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Wed, 18 Sep 2024 09:32:19 -0600 Subject: [PATCH] - Fix `Mark Read` node not working properly and update the docs for this node #111 --- src/matrix-mark-read.html | 202 +++++--------------------------------- src/matrix-mark-read.js | 12 ++- 2 files changed, 34 insertions(+), 180 deletions(-) diff --git a/src/matrix-mark-read.html b/src/matrix-mark-read.html index e74f899..98848b0 100644 --- a/src/matrix-mark-read.html +++ b/src/matrix-mark-read.html @@ -64,191 +64,35 @@ \ No newline at end of file + +

Usage

+

This node dynamically reads the room ID and event ID from the message or other properties using typed inputs, allowing you to configure where the values are sourced from. It retrieves the corresponding event and sends a "read" receipt to the Matrix server to mark the event as read. If successful, it will trigger the first output. If an error occurs (e.g., the event or room is not found), the second output is triggered with the error message.

+ diff --git a/src/matrix-mark-read.js b/src/matrix-mark-read.js index f9559ca..bc8eebe 100644 --- a/src/matrix-mark-read.js +++ b/src/matrix-mark-read.js @@ -56,7 +56,17 @@ module.exports = function(RED) { let roomId = getToValue(msg, node.roomType, node.roomValue), eventId = getToValue(msg, node.eventIdType, node.eventIdValue); - msg.payload = await node.server.matrixClient.setRoomReadMarkers(roomId, eventId); + const room = node.server.matrixClient.getRoom(roomId); + if (!room) { + throw new Error(`Room ${roomId} not found.`); + } + + const event = room.findEventById(eventId); + if (!event) { + throw new Error(`Event ${eventId} not found in room ${roomId}.`); + } + + await node.server.matrixClient.sendReceipt(event, "m.read") node.send([msg, null]); } catch(e) { msg.error = `Room pagination error: ${e}`;