project-robius / robrix

A Matrix chat client written in pure Rust using the Makepad UI toolkit and the Robius app dev framework
MIT License
62 stars 9 forks source link

Display `matrix.to` links to a specific user as "user tags" #84

Open kevinaboos opened 1 month ago

kevinaboos commented 1 month ago

Currently, when a message includes a tagged username, it is displayed just like a regular link. Instead, we should display it using a special visual element that is embedded into the message's HTML content (this isn't relevant for plaintext messages).

Element displays user tags as shown below, and calls them "User Pills" because the displayed element is pill-shaped:

image

Discord displays them like so:

image

Implementation

Makepad's HTML widget supports displaying custom widgets as inline HTML components, so it should be straightforward to create a new widget (e.g., UserTag) and include that as a possible template for any HTML URL that is a matrix.to link to a specific user. User tag links look like this:

<a href=\"https://matrix.to/#/@kevinaboos:matrix.org\">Kevin Boos</a>

The Robrix-specific HTML widget instance is defined here: https://github.com/project-robius/robrix/blob/61f49943b3bb89161dfca26c8cfaec98705f1f42/src/shared/html_or_plaintext.rs#L34-L36

We will likely need to completely replace Makepad's default HtmlLink widget with a custom widget that supports displaying either a regular HTML link or a special UserTag. Once that widget is implemented, we'll need to override the default handling for the a HTML tag (a link), which is specified here in the code: https://github.com/project-robius/robrix/blob/61f49943b3bb89161dfca26c8cfaec98705f1f42/src/shared/html_or_plaintext.rs#L61

A UserTag should contain an Avatar and a Label with the user's displayable name.

Upon being clicked, a UserTag should open the UserProfileSlidingPane, which an Avatar already supports as of #78. This was implemented in #90.

kevinaboos commented 1 month ago

PR #90 added support for handling when a user clicks on a matrix.to link or a user tag. But it doesn't change anything about how those links are displayed (they're still displayed as regular HTML links instead of the desired "User Pill" widget).