Skip to content

Instantly share code, notes, and snippets.

@wuast94
Last active September 8, 2024 14:59
Show Gist options
  • Select an option

  • Save wuast94/6df6eec865082f35d99c0b058811555b to your computer and use it in GitHub Desktop.

Select an option

Save wuast94/6df6eec865082f35d99c0b058811555b to your computer and use it in GitHub Desktop.

Revisions

  1. wuast94 revised this gist Sep 8, 2024. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions getReactedText.js
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,8 @@ This is a Test Change file

    - junk
    - some junk
    - This line will be edited
    - some other junk
    - this line will get removed
    - This line is now edited
    - some other junk we also edited
    - some more junk

    we will see
  2. wuast94 revised this gist Sep 8, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions getReactedText.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    This is a Test Change file

    - added
    - NOW ADDED
    - junk
    - some junk
    - added wiffll be edited
    - This line will be edited
    - some other junk
    - this line will get removed
    - some more junk

    we will see
  3. wuast94 revised this gist Sep 8, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions getReactedText.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    This is a Test Change file

    - added
    - NOW ADDED
    - some junk
    - added will be edited
    - added wiffll be edited
    - some other junk
    - added will be removed
    - some more junk

    we will see
  4. wuast94 revised this gist Sep 8, 2024. 1 changed file with 8 additions and 36 deletions.
    44 changes: 8 additions & 36 deletions getReactedText.js
    Original file line number Diff line number Diff line change
    @@ -1,38 +1,10 @@
    let matrixClient = global.get("matrixClient['@wuast94:3ddruckbremen.de']");
    let matrixOnline = global.get("matrixClientOnline['@wuast94:3ddruckbremen.de']");
    This is a Test Change file

    if (!matrixOnline) {
    msg.error = 'Matrix client not connected.';
    return [null, msg];
    }
    - added
    - some junk
    - added will be edited
    - some other junk
    - added will be removed
    - some more junk

    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]);
    });
    we will see
  5. wuast94 created this gist May 25, 2024.
    38 changes: 38 additions & 0 deletions getReactedText.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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]);
    });