mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-04 22:15:44 -04:00
chore(ui): simplify the fetch_replied_to_event method
This commit is contained in:
committed by
Stefan Ceriu
parent
db18e7fd74
commit
e5243e32be
@@ -69,10 +69,9 @@ use super::{
|
||||
item::TimelineUniqueId,
|
||||
subscriber::TimelineSubscriber,
|
||||
traits::{Decryptor, RoomDataProvider},
|
||||
DateDividerMode, Error, EventSendState, EventTimelineItem, InReplyToDetails, Message,
|
||||
PaginationError, Profile, ReactionsByKeyBySender, RepliedToEvent, TimelineDetails,
|
||||
TimelineEventItemId, TimelineFocus, TimelineItem, TimelineItemContent, TimelineItemKind,
|
||||
VirtualTimelineItem,
|
||||
DateDividerMode, Error, EventSendState, EventTimelineItem, InReplyToDetails, PaginationError,
|
||||
Profile, RepliedToEvent, TimelineDetails, TimelineEventItemId, TimelineFocus, TimelineItem,
|
||||
TimelineItemContent, TimelineItemKind, VirtualTimelineItem,
|
||||
};
|
||||
use crate::{
|
||||
timeline::{
|
||||
@@ -1344,17 +1343,11 @@ impl TimelineController {
|
||||
.ok_or(Error::EventNotInTimeline(TimelineEventItemId::EventId(event_id.to_owned())))?
|
||||
.clone();
|
||||
|
||||
let TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message),
|
||||
reactions,
|
||||
thread_root,
|
||||
in_reply_to,
|
||||
}) = item.content().clone()
|
||||
else {
|
||||
let TimelineItemContent::Aggregated(aggregated) = item.content().clone() else {
|
||||
debug!("Event is not a message");
|
||||
return Ok(());
|
||||
};
|
||||
let Some(in_reply_to) = in_reply_to else {
|
||||
let Some(in_reply_to) = aggregated.in_reply_to.clone() else {
|
||||
debug!("Event is not a reply");
|
||||
return Ok(());
|
||||
};
|
||||
@@ -1374,9 +1367,7 @@ impl TimelineController {
|
||||
index,
|
||||
&item,
|
||||
internal_id,
|
||||
&message,
|
||||
&reactions,
|
||||
&thread_root,
|
||||
&aggregated,
|
||||
&in_reply_to.event_id,
|
||||
self.room(),
|
||||
)
|
||||
@@ -1523,15 +1514,12 @@ impl<P: RoomDataProvider> TimelineController<P, (OlmMachine, OwnedRoomId)> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn fetch_replied_to_event(
|
||||
mut state: RwLockWriteGuard<'_, TimelineState>,
|
||||
index: usize,
|
||||
item: &EventTimelineItem,
|
||||
internal_id: TimelineUniqueId,
|
||||
message: &Message,
|
||||
reactions: &ReactionsByKeyBySender,
|
||||
thread_root: &Option<OwnedEventId>,
|
||||
aggregated: &AggregatedTimelineItemContent,
|
||||
in_reply_to: &EventId,
|
||||
room: &Room,
|
||||
) -> Result<TimelineDetails<Box<RepliedToEvent>>, Error> {
|
||||
@@ -1544,18 +1532,12 @@ async fn fetch_replied_to_event(
|
||||
// Replace the item with a new timeline item that has the fetching status of the
|
||||
// replied-to event to pending.
|
||||
trace!("Setting in-reply-to details to pending");
|
||||
let in_reply_to_details = Some(InReplyToDetails {
|
||||
event_id: in_reply_to.to_owned(),
|
||||
event: TimelineDetails::Pending,
|
||||
});
|
||||
let in_reply_to_details =
|
||||
InReplyToDetails { event_id: in_reply_to.to_owned(), event: TimelineDetails::Pending };
|
||||
|
||||
let event_item =
|
||||
item.with_content(TimelineItemContent::Aggregated(AggregatedTimelineItemContent {
|
||||
kind: AggregatedTimelineItemContentKind::Message(message.clone()),
|
||||
reactions: reactions.clone(),
|
||||
thread_root: thread_root.clone(),
|
||||
in_reply_to: in_reply_to_details,
|
||||
}));
|
||||
let event_item = item.with_content(TimelineItemContent::Aggregated(
|
||||
aggregated.with_in_reply_to(in_reply_to_details),
|
||||
));
|
||||
|
||||
let new_timeline_item = TimelineItem::new(event_item, internal_id);
|
||||
state.items.replace(index, new_timeline_item);
|
||||
|
||||
@@ -56,4 +56,8 @@ impl AggregatedTimelineItemContent {
|
||||
pub fn is_threaded(&self) -> bool {
|
||||
self.thread_root.is_some()
|
||||
}
|
||||
|
||||
pub fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
|
||||
Self { in_reply_to: Some(in_reply_to), ..self.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user