project-robius / robrix

Robrix: a multi-platform Matrix chat client written in Rust using the Makepad UI toolkit and the Robius app dev framework
MIT License
120 stars 19 forks source link

Properly handle `matrix.to` links to a specific event (message) #222

Open kevinaboos opened 3 weeks ago

kevinaboos commented 3 weeks ago

These links are special and should be handled via in-app actions rather than by opening them as a regular URL in the system browser.

There is a separate issue for handling matrix.to links to a specific Room, which is easier: #87

Implementation

Currently, Robrix just ignores matrix.to links that are clicked on, as seen in the code here: https://github.com/project-robius/robrix/blob/61f49943b3bb89161dfca26c8cfaec98705f1f42/src/home/room_screen.rs#L857-L868

Note that issue #84 already covers one specific case of this: links to Users, which should be displayed as a special UserTag widget.

This issue covers one other type of matrix.to links:

Links to a message

We should create a MessageTag widget similar to the RoomTag widget mentioned above, which looks like this in Element:

image

Upon click, we should determine which room the linked message belongs to. If the current user has already joined that room, we should open that room's timeline view and then attempt to jump to the event in that room with the given EventId. That message should be highlighted temporarily for emphasis.

If the user has not yet joined the room containing that linked message, we should open the same room preview as we do for direct links to the room itself. In this case, I don't think there's any other actions we can take -- but we should investigate whether it's possible to obtain a preview of a specific message without having joined that room.

Important Note: it is a common case for a user to be unable to view a specific message, as it may have occurred before they had the permissions to view messages in that room. So we must handle that error case gracefully; here's what Element shows in that case:

image

Difficulty surrounding timeline focus mode

For this, we need to temporarily create a new timeline that is focused on the specific linked-to event. This is difficult because although the Matrix SDK claims it supports changing the focus mode of a given timeline, it does not actually support that, so we cannot simply re-use an existing timeline for the room containing that event.

Thus, we have to create a new separate timeline instance using TimelineBuilder::with_focus() (using TimelineFocus::Event), and then just use that new timeline instance as a temporary way to preview this Event.

tyreseluo commented 2 weeks ago

@kevinaboos Should we create three different tags for each of them or combine them into one tag and display them in a single tag, since they all look similar?

  1. UserTag #84
  2. RoomTag #87
  3. MessageTag #222
kevinaboos commented 2 weeks ago

those are three different tags, but of course you can create one underlying view for a "pill" UI element that gets re-used for all three tag types. That would be a good way to implement it.