Skip to content

Instantly share code, notes, and snippets.

@wuast94
Created May 25, 2024 23:50
Show Gist options
  • Save wuast94/6df6eec865082f35d99c0b058811555b to your computer and use it in GitHub Desktop.
Save wuast94/6df6eec865082f35d99c0b058811555b to your computer and use it in GitHub Desktop.
let matrixClient = global.get("matrixClient['@wuast94:3ddruckbremen.de']");
let matrixOnline = global.get("matrixClientOnline['@wuast94:3ddruckbremen.de']");
if (!matrixOnline) {
msg.error = 'Matrix client not connected.';
return [null, msg];
}
async function getMessageContentWithReaction(roomId, reactionEventId) {
try {
const reactionEvent = await matrixClient.fetchRoomEvent(roomId, reactionEventId);
if (reactionEvent.type === "m.reaction") {
const relatesTo = reactionEvent.content["m.relates_to"];
if (relatesTo && relatesTo["event_id"]) {
const originalEventId = relatesTo["event_id"];
const originalEvent = await matrixClient.fetchRoomEvent(roomId, originalEventId);
return originalEvent.content;
} else {
throw new Error("Invalid reaction event: missing 'm.relates_to' or 'event_id'.");
}
} else {
throw new Error("Provided event is not a reaction.");
}
} catch (error) {
throw error;
}
}
getMessageContentWithReaction(msg.topic, msg.eventId)
.then(content => {
msg.originalContent = content;
node.send([msg, null]);
})
.catch(error => {
node.warn("Error fetching message content: " + error);
msg.error = error;
node.send([null, msg]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment