Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix garbled replies to replies due to invalid reply formatting #1202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ichthyosaurus
Copy link

Due to invalid formatting, replies to replies became garbled, causing display issues in some clients. Hydrogen itself managed
to display the replies correctly but other clients and bridges struggled because they were actually using the fallbacks.

The PR fixes the formatting of reply fallbacks (current spec: https://spec.matrix.org/v1.12/client-server-api/#fallbacks-for-rich-replies) and "mentions" the replied-to user when replying to a message as per https://spec.matrix.org/v1.12/client-server-api/#mentioning-the-replied-to-user.

In the examples below, I used a compliant client to send "first message", and to sent "second message" as a reply to "first message". I then sent "Hydrogen message" using Hydrogen as a reply to "second message".

Old, invalid formatting of reply fallbacks:

{
  "content": {
    "body": "> <@user:example.org> > <@user:example.org> first message\n> \n> second message\n\nHydrogen message",
    "format": "org.matrix.custom.html",
    "formatted_body": "<mx-reply><blockquote>In reply to <a href=\"https://matrix.to/#/@user:example.org\">User</a><br /><mx-reply><blockquote><a href=\"https://matrix.to/#/!xxxxxxxxxxxxxxxxxx:example.org/$event\">In reply to</a> <a href=\"https://matrix.to/#/@user:example.org\">@user:example.org</a><br>first message</blockquote></mx-reply>second message</blockquote></mx-reply>Hydrogen message",
    "m.relates_to": {
      "m.in_reply_to": {
        "event_id": "$event"
      }
    },
    "msgtype": "m.text"
  },
  "event_id": "$...",
  "sender": "@user:example.org",
  "type": "m.room.message",
}
<!-- only the formatted_body part: -->
<mx-reply>
    <blockquote>
        In reply to
        <a href=\"https://matrix.to/#/@user:example.org\">
            User
        </a>
        <br />
        <mx-reply>
            <blockquote>
                <a href=\"https://matrix.to/#/!xxxxxxxxxxxxxxxxxx:example.org/$event\">
                    In reply to
                </a>
                <a href=\"https://matrix.to/#/@user:example.org\">
                    @user:example.org
                </a>
                <br>
                first message
            </blockquote>
        </mx-reply>
        second message
    </blockquote>
</mx-reply>
Hydrogen message

New, correct formatting of reply fallbacks:

{
  "content": {
    "body": "> <@user:example.org> second message\n\nHydrogen ",
    "format": "org.matrix.custom.html",
    "formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!xxxxxxxxxxxxxxxxxx%3Aexample.org/%24event\">In reply to</a><a href=\"https://matrix.to/#/@user:example.org\">@user:example.org</a><br />second message</blockquote></mx-reply>Hydrogen message",
    "m.mentions": {
      "user_ids": [
        "@user:example.org"
      ]
    },
    "m.relates_to": {
      "m.in_reply_to": {
        "event_id": "$event"
      }
    },
    "msgtype": "m.text"
  },
  "event_id": "$...",
  "sender": "@user:example.org",
  "type": "m.room.message",
}
<!-- only the formatted_body part: -->
<mx-reply>
    <blockquote>
        <a href=\"https://matrix.to/#/!xxxxxxxxxxxxxxxxxx%3Aexample.org/%24event\">
            In reply to
        </a>
        <a href=\"https://matrix.to/#/@user:example.org\">
            @user:example.org
        </a>
        <br />
        second message
    </blockquote>
</mx-reply>
Hydrogen message

Reply fallbacks are actively being removed in the upcoming spec but that doesn't mean that Hydrogen should keep the old bugged code in place.

MSCs for the upcoming spec:

Signed-off-by: Mirian Margiani <mixosaurus+ichthyo@pm.me>
Due to invalid formatting, replies to replies became garbled,
causing display issues in some clients. Hydrogen itself managed
to display the replies correctly but other clients and bridges
struggled because they were actually using the fallbacks.

Current spec: https://spec.matrix.org/v1.12/client-server-api/#fallbacks-for-rich-replies

Reply fallbacks are actively being removed in the upcoming spec but
that doesn't mean that Hydrogen should keep the old bugged code in place.

Upcoming MSCs:
- matrix-org/matrix-spec-proposals#2781
- matrix-org/matrix-spec-proposals#3676
- spec: matrix-org/matrix-spec#1994

Signed-off-by: Mirian Margiani <mixosaurus+ichthyo@pm.me>
Mention the replied-to user when replying to a message as per
https://spec.matrix.org/v1.12/client-server-api/#mentioning-the-replied-to-user

Signed-off-by: Mirian Margiani <mixosaurus+ichthyo@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant