Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

Add support for modifying messages #54

Closed skylord123 closed 2 years ago

skylord123 commented 2 years ago

I've been thinking about this for a while. I think it would be best to just add a checkbox option to the send-message node that says "If msg.eventId is set replace existing message" or something similar. Any message coming in with this option checked and having msg.eventId will be updated with the new content.

There is one problem though. If you try to remove a message you need to remove the parent message's eventId. This means if you modify a message then have a redact/remove event node downstream it will only remove the edit and not the actual message. We will need to test this and possibly add an explanation to the node documentation.

skylord123 commented 2 years ago

Here is an example of updating an HTML message and how it changes (notice how the eventId changes and is referenced in the edit)

Original message Event ID: $cKvr2jf694jUUCGkHXClfzLffhuH1JiRQBfW1U9p4vo

{
  "type": "m.room.message",
  "content": {
    "msgtype": "m.text",
    "body": "`how are you?`",
    "format": "org.matrix.custom.html",
    "formatted_body": "<code>how are you?</code>"
  }
}

Modified message Event ID: $ZY3fduUGguy-l7-8G-tjw-glDvzcizc7O30_Z7mUr0Q

{
  "type": "m.room.message",
  "content": {
    "m.new_content": {
      "msgtype": "m.text",
      "body": "> good you?",
      "format": "org.matrix.custom.html",
      "formatted_body": "<blockquote>\ngood you?\n</blockquote>\n"
    },
    "m.relates_to": {
      "rel_type": "m.replace",
      "event_id": "$cKvr2jf694jUUCGkHXClfzLffhuH1JiRQBfW1U9p4vo"
    },
    "msgtype": "m.text",
    "body": " * > good you?",
    "format": "org.matrix.custom.html",
    "formatted_body": " * <blockquote>\ngood you?\n</blockquote>\n"
  }
}
skylord123 commented 2 years ago

Here is an example of a normal message being modified:

Original message Event ID: $DLvFay5Y-EuIRqotUqkVgjV4eblyEaFj-nrUOPmd1X4

{
  "type": "m.room.message",
  "content": {
    "msgtype": "m.text",
    "body": "yay"
  }
}

Modified message Event ID: $DoaZJ4vy22AwOvEc3syZF9kWOxZXNd1p4fdRqzkaSi0

{
  "type": "m.room.message",
  "content": {
    "m.new_content": {
      "msgtype": "m.text",
      "body": "what"
    },
    "m.relates_to": {
      "rel_type": "m.replace",
      "event_id": "$DLvFay5Y-EuIRqotUqkVgjV4eblyEaFj-nrUOPmd1X4"
    },
    "msgtype": "m.text",
    "body": " * what"
  }
}