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

latest event: allow selecting an edit to the previous latest event as a viable latest event #3764

Closed
wants to merge 6 commits into from
20 changes: 11 additions & 9 deletions crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use ruma::{
AnyFullStateEventContent, AnySyncMessageLikeEvent, AnySyncTimelineEvent,
BundledMessageLikeRelations, FullStateEventContent, MessageLikeEventType, StateEventType,
},
EventId, OwnedDeviceId, OwnedMxcUri, OwnedUserId, RoomVersionId, UserId,
OwnedDeviceId, OwnedMxcUri, OwnedUserId, RoomVersionId, UserId,
};
use tracing::{debug, warn};

Expand Down Expand Up @@ -125,7 +125,8 @@ impl TimelineItemContent {
match event {
AnySyncTimelineEvent::MessageLike(ref msg_like) => match msg_like {
AnySyncMessageLikeEvent::RoomMessage(room_msg) => {
Some(Self::from_suitable_latest_event_content(room_msg))
let bundled_relations = msg_like.relations();
Some(Self::from_suitable_latest_event_content(room_msg, bundled_relations))
}
AnySyncMessageLikeEvent::Sticker(sticker) => {
Some(Self::from_suitable_latest_sticker_content(sticker))
Expand Down Expand Up @@ -158,29 +159,30 @@ impl TimelineItemContent {
/// Given some message content that is from an event that we have already
/// determined is suitable for use as a latest event in a message preview,
/// extract its contents and wrap it as a `TimelineItemContent`.
fn from_suitable_latest_event_content(event: &SyncRoomMessageEvent) -> TimelineItemContent {
fn from_suitable_latest_event_content(
event: &SyncRoomMessageEvent,
relations: BundledMessageLikeRelations<AnySyncMessageLikeEvent>,
) -> TimelineItemContent {
match event {
SyncRoomMessageEvent::Original(event) => {
// Grab the content of this event
// Grab the content of this event.
let event_content = event.content.clone();

// We don't have access to any relations via the `AnySyncTimelineEvent` (I think
// - andyb) so we pretend there are none. This might be OK for
// the message preview use case.
Copy link
Member

Choose a reason for hiding this comment

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

Woohoo, glad to see this go!

let relations = BundledMessageLikeRelations::new();

// If this message is a reply, we would look up in this list the message it was
// replying to. Since we probably won't show this in the message preview,
// it's probably OK to supply an empty list here.
//
// `Message::from_event` marks the original event as `Unavailable` if it can't
// be found inside the timeline_items.
let timeline_items = Vector::new();

TimelineItemContent::Message(Message::from_event(
event_content,
relations,
&timeline_items,
))
}

SyncRoomMessageEvent::Redacted(_) => TimelineItemContent::RedactedMessage,
}
}
Expand Down