Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fetching an event's content by its ID gives the latest edit content rather than the original #10310

Closed
edwargix opened this issue Jul 4, 2021 · 1 comment · Fixed by #12476
Labels
A-Event-Endpoint Fetch a single event, /_matrix/client/r0/rooms/{roomId}/event/{eventId} (`RoomEventServlet`) P3 (OBSOLETE: use S- labels.) Approved backlog: not yet scheduled, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@edwargix
Copy link
Contributor

edwargix commented Jul 4, 2021

Description

Fetching an event's content by its ID with the GET /_matrix/client/r0/rooms/{roomId}/event/{eventId} endpoint yields the content of the latest edit event rather than the content consistent with the ID.

Steps to reproduce

# send an m.text event with content "test" and then
$ EVENTID='$0_lK-IgCcbad6aPp-zdCqBaQuMg85g4-vubakBknDe8'  # ID of the sent event
$ curl -s "https://$HOST/_matrix/client/r0/rooms/$ROOMID/event/$EVENTID?access_token=$TOKEN" | jq .content
{
  "msgtype": "m.text",
  "body": "test"
}
# edit the content of the event to "test edited content" (done via Element here) and fetch again:
$ curl -s "https://$HOST/_matrix/client/r0/rooms/$ROOMID/event/$EVENTID?access_token=$TOKEN" | jq .content
{
  "msgtype": "m.text",
  "body": "test edited content"
}
$ curl -s "https://$HOST/_matrix/client/r0/rooms/$ROOMID/event/$EVENTID?access_token=$TOKEN" | jq .unsigned
{
  "age": 483762,
  "m.relations": {
    "m.replace": {
      "event_id": "$xNM2Um7jlk6jEMvGzlRPc7YW6x3nVhAOOs36WJq5kfk",
      "origin_server_ts": 1625420884120,
      "sender": "@euclid:hnitbjorg.xyz"
    }
  }
}
$ NEWEVENTID='$xNM2Um7jlk6jEMvGzlRPc7YW6x3nVhAOOs36WJq5kfk'
$ curl -s "https://$HOST/_matrix/client/r0/rooms/$ROOMID/event/$NEWEVENTID?access_token=$TOKEN" | jq .content 
{
  "m.new_content": {
    "msgtype": "m.text",
    "body": "test edited content"
  },
  "m.relates_to": {
    "rel_type": "m.replace",
    "event_id": "$0_lK-IgCcbad6aPp-zdCqBaQuMg85g4-vubakBknDe8"
  },
  "msgtype": "m.text",
  "body": " * test edited content"
}

I asked whether there's a way to get an event's original content in the #matrix-spec room without doing a full /sync and many concluded [ref] that the behavior outlined above is a bug (or at least ambiguously specified).

Version information

  • Homeserver: non-matrix.org server

If not matrix.org:

@babolivier babolivier added P3 (OBSOLETE: use S- labels.) Approved backlog: not yet scheduled, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Jul 5, 2021
@richvdh
Copy link
Member

richvdh commented Jul 22, 2021

Useful context from the linked discussion:

  • @turt2live was surprised by this behaviour and thought it should return the original

  • MSC2675 had:

    FIXME: we need to spell out that this API [/relations] should return the original message when paginating over m.replace relations for a given message. Synapse currently looks to include this as an original_event field alongside chunk on all relations, which feels very redundant when we only need it for edits. Either we specialcase it for edits, or we just have the client go call /event to grab the contents of the original?

    ... which strongly implies this behaviour is incorrect.

  • @tulir linked to the place it is happening: https://github.com/matrix-org/synapse/blob/v1.36.0/synapse/events/utils.py#L401-L426

See also https://github.com/matrix-org/matrix-spec-proposals/pull/2675/files/8eec329d7d5c525386e2c06cbc9a2ba4e99519d3#r451146138 which discussed this further.

I think we'd welcome PRs to fix this (presumably by passing a apply_edits parameter into serialize_event).

richvdh added a commit that referenced this issue Apr 14, 2022
richvdh added a commit that referenced this issue Apr 19, 2022
…its (#12476)

This is what the MSC (now) requires. Fixes #10310.
@MadLittleMods MadLittleMods added the A-Event-Endpoint Fetch a single event, /_matrix/client/r0/rooms/{roomId}/event/{eventId} (`RoomEventServlet`) label Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Event-Endpoint Fetch a single event, /_matrix/client/r0/rooms/{roomId}/event/{eventId} (`RoomEventServlet`) P3 (OBSOLETE: use S- labels.) Approved backlog: not yet scheduled, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants