mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 02:55:47 -04:00
chore(ui): move event based relation handling to TimelineMetadata and out of the TimelineAction
This commit is contained in:
committed by
Benjamin Bouvier
parent
ba53390547
commit
dc24365ddf
@@ -308,6 +308,32 @@ impl TimelineMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn process_event_relations(
|
||||
&mut self,
|
||||
event: AnySyncTimelineEvent,
|
||||
raw_event: &Raw<AnySyncTimelineEvent>,
|
||||
bundled_edit_encryption_info: Option<Arc<EncryptionInfo>>,
|
||||
timeline_items: &Vector<Arc<TimelineItem>>,
|
||||
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
|
||||
match event {
|
||||
AnySyncTimelineEvent::MessageLike(ev) => match ev.original_content() {
|
||||
Some(content) => {
|
||||
let remote_ctx = Some(RemoteEventContext {
|
||||
event_id: ev.event_id(),
|
||||
raw_event,
|
||||
relations: ev.relations(),
|
||||
bundled_edit_encryption_info,
|
||||
});
|
||||
|
||||
self.process_content_relations(&content, remote_ctx, timeline_items)
|
||||
}
|
||||
|
||||
None => (None, None),
|
||||
},
|
||||
_ => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn process_content_relations(
|
||||
&mut self,
|
||||
content: &AnyMessageLikeEventContent,
|
||||
|
||||
@@ -54,7 +54,7 @@ use tokio::sync::{RwLock, RwLockWriteGuard};
|
||||
use tracing::{debug, error, field::debug, info, instrument, trace, warn};
|
||||
|
||||
pub(super) use self::{
|
||||
metadata::{RelativePosition, RemoteEventContext, TimelineMetadata},
|
||||
metadata::{RelativePosition, TimelineMetadata},
|
||||
observable_items::{
|
||||
AllRemoteEvents, ObservableItems, ObservableItemsEntry, ObservableItemsTransaction,
|
||||
ObservableItemsTransactionEntry,
|
||||
|
||||
@@ -206,10 +206,10 @@ impl<'a> TimelineStateTransaction<'a> {
|
||||
event.raw(),
|
||||
room_data_provider,
|
||||
None,
|
||||
&self.meta,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&self.items,
|
||||
&mut self.meta,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -620,6 +620,13 @@ impl<'a> TimelineStateTransaction<'a> {
|
||||
{
|
||||
// Classical path: the event is valid, can be deserialized, everything is alright.
|
||||
Ok(event) => {
|
||||
let (in_reply_to, thread_root) = self.meta.process_event_relations(
|
||||
event.clone(),
|
||||
&raw,
|
||||
bundled_edit_encryption_info,
|
||||
&self.items,
|
||||
);
|
||||
|
||||
let should_add =
|
||||
self.should_add_event_item(room_data_provider, settings, &event, position);
|
||||
(
|
||||
@@ -631,11 +638,11 @@ impl<'a> TimelineStateTransaction<'a> {
|
||||
event,
|
||||
&raw,
|
||||
room_data_provider,
|
||||
thread_summary,
|
||||
utd_info,
|
||||
bundled_edit_encryption_info,
|
||||
&self.items,
|
||||
&mut self.meta,
|
||||
&self.meta,
|
||||
in_reply_to,
|
||||
thread_root,
|
||||
thread_summary,
|
||||
)
|
||||
.await,
|
||||
should_add,
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
|
||||
use as_variant::as_variant;
|
||||
use imbl::Vector;
|
||||
use indexmap::IndexMap;
|
||||
use matrix_sdk::{
|
||||
crypto::types::events::UtdCause,
|
||||
@@ -45,7 +44,7 @@ use tracing::{debug, error, field::debug, instrument, trace, warn};
|
||||
use super::{
|
||||
controller::{
|
||||
find_item_and_apply_aggregation, Aggregation, AggregationKind, ObservableItemsTransaction,
|
||||
PendingEditKind, RemoteEventContext, TimelineMetadata, TimelineStateTransaction,
|
||||
PendingEditKind, TimelineMetadata, TimelineStateTransaction,
|
||||
},
|
||||
date_dividers::DateDividerAdjuster,
|
||||
event_item::{
|
||||
@@ -185,11 +184,11 @@ impl TimelineAction {
|
||||
event: AnySyncTimelineEvent,
|
||||
raw_event: &Raw<AnySyncTimelineEvent>,
|
||||
room_data_provider: &P,
|
||||
thread_summary: Option<ThreadSummary>,
|
||||
unable_to_decrypt_info: Option<UnableToDecryptInfo>,
|
||||
bundled_edit_encryption_info: Option<Arc<EncryptionInfo>>,
|
||||
timeline_items: &Vector<Arc<TimelineItem>>,
|
||||
meta: &mut TimelineMetadata,
|
||||
meta: &TimelineMetadata,
|
||||
in_reply_to: Option<InReplyToDetails>,
|
||||
thread_root: Option<OwnedEventId>,
|
||||
thread_summary: Option<ThreadSummary>,
|
||||
) -> Option<Self> {
|
||||
let room_version = room_data_provider.room_version();
|
||||
|
||||
@@ -238,24 +237,12 @@ impl TimelineAction {
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
let content = AnyMessageLikeEventContent::RoomEncrypted(content);
|
||||
|
||||
let remote_ctx = Some(RemoteEventContext {
|
||||
event_id: ev.event_id(),
|
||||
raw_event,
|
||||
relations: ev.relations(),
|
||||
bundled_edit_encryption_info,
|
||||
});
|
||||
|
||||
let (in_reply_to, thread_root) =
|
||||
meta.process_content_relations(&content, remote_ctx, timeline_items);
|
||||
|
||||
// If we get here, it means that some part of the code has created a
|
||||
// `TimelineEvent` containing an `m.room.encrypted` event without
|
||||
// decrypting it. Possibly this means that encryption has not been
|
||||
// configured. We treat it the same as any other message-like event.
|
||||
return Self::from_content(
|
||||
content,
|
||||
AnyMessageLikeEventContent::RoomEncrypted(content),
|
||||
in_reply_to,
|
||||
thread_root,
|
||||
thread_summary,
|
||||
@@ -264,16 +251,6 @@ impl TimelineAction {
|
||||
}
|
||||
|
||||
Some(content) => {
|
||||
let remote_ctx = Some(RemoteEventContext {
|
||||
event_id: ev.event_id(),
|
||||
raw_event,
|
||||
relations: ev.relations(),
|
||||
bundled_edit_encryption_info,
|
||||
});
|
||||
|
||||
let (in_reply_to, thread_root) =
|
||||
meta.process_content_relations(&content, remote_ctx, timeline_items);
|
||||
|
||||
return Self::from_content(content, in_reply_to, thread_root, thread_summary);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,16 +113,23 @@ impl EmbeddedEvent {
|
||||
// We don't need to fill the thread information of an embedded reply.
|
||||
let thread_summary = None;
|
||||
|
||||
let (in_reply_to, thread_root) = meta.process_event_relations(
|
||||
event.clone(),
|
||||
&raw_event,
|
||||
bundled_edit_encryption_info,
|
||||
timeline_items,
|
||||
);
|
||||
|
||||
let sender = event.sender().to_owned();
|
||||
let action = TimelineAction::from_event(
|
||||
event,
|
||||
&raw_event,
|
||||
room_data_provider,
|
||||
thread_summary,
|
||||
unable_to_decrypt_info,
|
||||
bundled_edit_encryption_info,
|
||||
timeline_items,
|
||||
meta,
|
||||
in_reply_to,
|
||||
thread_root,
|
||||
thread_summary,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user