Skip to content

feat(ui): add custom event content to timeline items#6450

Draft
niclashoyer wants to merge 1 commit into
matrix-org:mainfrom
niclashoyer:custom-content
Draft

feat(ui): add custom event content to timeline items#6450
niclashoyer wants to merge 1 commit into
matrix-org:mainfrom
niclashoyer:custom-content

Conversation

@niclashoyer

@niclashoyer niclashoyer commented Apr 14, 2026

Copy link
Copy Markdown

This adds the actual raw event to OtherMessageLike timeline events, so that it is possible to decode the custom events and display them in clients that use the ui/timeline api.

I did not document this for now or add new tests, as I'm looking for feedback first. As this is my first contribution to this crate, I'd like to clarify if this approach is the right thing to do, or if there is a more idiomatic way to pass down raw ruma events.

With this change the usual case does not change. To actually retrieve the custom events in the timeline the timeline event filter needs to be changed from the default to include wanted custom events. Now if the timeline contains a custom (remote) event, the raw event is cloned and passed to the client as a field in OtherMessageLike. For local events this is not supported right now.

Example usage to decode custom events (kinda pseudo code):

#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "com.example.message", kind = MessageLike)]
pub struct ExampleMessageContent {
    #[serde(rename = "fooBar")]
    foo_bar: u32,
}

/* … */

let timeline = room.timeline_builder()
    .event_filter(|_, _| true) // change filter to return all events
    .build()
    .await
    .expect("could not create timeline");

let (evs, mut diffs) = timeline.subscribe().await;

for event in evs.iter()
    match event.content() {
        TimelineItemContent::MsgLike(MsgLikeContent { kind: MsgLikeKind::Other(o), .. }) => {
            let ex = o.raw_event().as_ref().map(|x| x.deserialize_as_unchecked::<MessageLikeEvent<ExampleMessageContent>>());
            println!("{:?}", ex); // Some(Ok(Original(OriginalMessageLikeEvent …
        }
    }
}

cc #6177

  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

Signed-off-by: Niclas Hoyer <info@niclashoyer.de>
@codspeed-hq

codspeed-hq Bot commented Apr 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing niclashoyer:custom-content (092bea8) with main (dab87b7)

Open in CodSpeed

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