Skip to content

MSC4269: Unambiguous mentions in body #4269

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions proposals/4269-unambiguous-mentions-in-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# MSC4269: Unambiguous mentions in body

The use of display names makes it difficult to parse user mentions from a message body. Clients can
also make it difficult to type user IDs without having them replaced with a mention.

Some clients, such as bots, have no use for or do not want to deal with the complexity of parsing
the pseudo-HTML of the `formatted_body`. In addition, the `m.mentions` added by [MSC3952] is not
enough, either, as the listed user IDs lack the context of the message body.

Translating the display names in the message body back to user IDs is difficult, if not impossible.
However, the reverse operation - translating unambiguous user IDs in the body into display names -
is trivial in comparison.

Thus it is proposed that the message `body` should contain user IDs instead of display names.

## Proposal

The specified client behavior for user and room mentions is modified so that the event's `body`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking to the spec here might help in better understanding the proposal.

Suggested change
The specified client behavior for user and room mentions is modified so that the event's `body`
The [specified client behavior](https://spec.matrix.org/v1.13/client-server-api/#user-and-room-mentions) for user and room mentions is modified so that the event's `body`

should contain the unambiguous user ID, canonical room alias or room ID instead of the anchor's
text component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, applying this to the example from the spec would lead to the following?

Suggested change
```json5
{
"body": "Hello @alice:example.org!",
"msgtype": "m.text",
"format": "org.matrix.custom.html",
"formatted_body": "Hello <a href='https://matrix.to/#/@alice:example.org'>Alice</a>!",
"m.mentions": {
"user_ids": ["@alice:example.org"]
}
}

## Potential issues

Some clients, especially bridges, might rely on the body containing the display name for a good user
experience. However, it would not be difficult to modify such a client to translate user IDs in the
message body to display names.
Comment on lines +24 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would make it impossible to send a literal MXID in body without having it transformed to the display name upon display?

It would also be a breaking change which could possibly require a new room version.


## Alternatives

- Change the spec so that the anchor's text component is the user ID. It would make user mentions
more consistent with room mentions. This changes the `formatted_body` as well, potentially
requiring more changes to clients.

- Specify the use of markdown links in the `body` matching the anchors in the `formatted_body`.
While easier to parse, it's not as simple as just the user ID.

- Bracket display names in the `body` somehow, making it possible to look them up, perhaps with the
help of `m.mentions`. However, they remain ambiguous.

## Security considerations

None.

## Unstable prefix

None.

## Dependencies

None.

[MSC3952]: https://github.com/matrix-org/matrix-spec-proposals/pull/3952