mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 07:56:55 -04:00
refactor(timeline): rename TimelineFocusData to TimelineFocusKind
This commit is contained in:
@@ -38,7 +38,7 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
timeline::{
|
||||
controller::TimelineFocusData,
|
||||
controller::TimelineFocusKind,
|
||||
event_item::{
|
||||
extract_bundled_edit_event_json, extract_poll_edit_content,
|
||||
extract_room_msg_edit_content,
|
||||
@@ -318,7 +318,7 @@ impl TimelineMetadata {
|
||||
raw_event: &Raw<AnySyncTimelineEvent>,
|
||||
bundled_edit_encryption_info: Option<Arc<EncryptionInfo>>,
|
||||
timeline_items: &Vector<Arc<TimelineItem>>,
|
||||
timeline_focus: &TimelineFocusData<P>,
|
||||
timeline_focus: &TimelineFocusKind<P>,
|
||||
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
|
||||
if let AnySyncTimelineEvent::MessageLike(ev) = event {
|
||||
if let Some(content) = ev.original_content() {
|
||||
@@ -349,7 +349,7 @@ impl TimelineMetadata {
|
||||
content: &AnyMessageLikeEventContent,
|
||||
remote_ctx: Option<RemoteEventContext<'_>>,
|
||||
timeline_items: &Vector<Arc<TimelineItem>>,
|
||||
timeline_focus: &TimelineFocusData<P>,
|
||||
timeline_focus: &TimelineFocusKind<P>,
|
||||
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
|
||||
match content {
|
||||
AnyMessageLikeEventContent::Sticker(content) => {
|
||||
@@ -453,7 +453,7 @@ impl TimelineMetadata {
|
||||
fn extract_reply_and_thread_root<P: RoomDataProvider>(
|
||||
relates_to: Option<RelationWithoutReplacement>,
|
||||
timeline_items: &Vector<Arc<TimelineItem>>,
|
||||
timeline_focus: &TimelineFocusData<P>,
|
||||
timeline_focus: &TimelineFocusKind<P>,
|
||||
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
|
||||
let mut thread_root = None;
|
||||
|
||||
@@ -464,7 +464,7 @@ impl TimelineMetadata {
|
||||
RelationWithoutReplacement::Thread(thread) => {
|
||||
thread_root = Some(thread.event_id);
|
||||
|
||||
if matches!(timeline_focus, TimelineFocusData::Thread { .. })
|
||||
if matches!(timeline_focus, TimelineFocusKind::Thread { .. })
|
||||
&& thread.is_falling_back
|
||||
{
|
||||
// In general, a threaded event is marked as a response to the previous message
|
||||
|
||||
@@ -92,8 +92,12 @@ mod state_transaction;
|
||||
pub(super) use aggregations::*;
|
||||
|
||||
/// Data associated to the current timeline focus.
|
||||
///
|
||||
/// This is the private counterpart of [`TimelineFocus`], and it is an augmented
|
||||
/// version of it, including extra state that makes it useful over the lifetime
|
||||
/// of a timeline.
|
||||
#[derive(Debug)]
|
||||
pub(in crate::timeline) enum TimelineFocusData<P: RoomDataProvider> {
|
||||
pub(in crate::timeline) enum TimelineFocusKind<P: RoomDataProvider> {
|
||||
/// The timeline receives live events from the sync.
|
||||
Live {
|
||||
/// Whether to hide in-thread events from the timeline.
|
||||
@@ -134,7 +138,7 @@ pub(super) struct TimelineController<P: RoomDataProvider = Room, D: Decryptor =
|
||||
state: Arc<RwLock<TimelineState<P>>>,
|
||||
|
||||
/// Focus data.
|
||||
focus: Arc<TimelineFocusData<P>>,
|
||||
focus: Arc<TimelineFocusKind<P>>,
|
||||
|
||||
/// A [`RoomDataProvider`] implementation, providing data.
|
||||
///
|
||||
@@ -275,13 +279,13 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
unable_to_decrypt_hook: Option<Arc<UtdHookManager>>,
|
||||
is_room_encrypted: bool,
|
||||
) -> Self {
|
||||
let focus_data = match focus {
|
||||
let focus = match focus {
|
||||
TimelineFocus::Live { hide_threaded_events } => {
|
||||
TimelineFocusData::Live { hide_threaded_events }
|
||||
TimelineFocusKind::Live { hide_threaded_events }
|
||||
}
|
||||
TimelineFocus::Event { target, num_context_events, hide_threaded_events } => {
|
||||
let paginator = Paginator::new(room_data_provider.clone());
|
||||
TimelineFocusData::Event {
|
||||
TimelineFocusKind::Event {
|
||||
paginator,
|
||||
event_id: target,
|
||||
num_context_events,
|
||||
@@ -289,7 +293,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
}
|
||||
}
|
||||
|
||||
TimelineFocus::Thread { root_event_id, num_events } => TimelineFocusData::Thread {
|
||||
TimelineFocus::Thread { root_event_id, num_events } => TimelineFocusKind::Thread {
|
||||
loader: ThreadedEventsLoader::new(
|
||||
room_data_provider.clone(),
|
||||
root_event_id.clone(),
|
||||
@@ -299,7 +303,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
},
|
||||
|
||||
TimelineFocus::PinnedEvents { max_events_to_load, max_concurrent_requests } => {
|
||||
TimelineFocusData::PinnedEvents {
|
||||
TimelineFocusKind::PinnedEvents {
|
||||
loader: PinnedEventsLoader::new(
|
||||
Arc::new(room_data_provider.clone()),
|
||||
max_events_to_load as usize,
|
||||
@@ -309,9 +313,9 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
}
|
||||
};
|
||||
|
||||
let focus_data = Arc::new(focus_data);
|
||||
let focus = Arc::new(focus);
|
||||
let state = Arc::new(RwLock::new(TimelineState::new(
|
||||
focus_data.clone(),
|
||||
focus.clone(),
|
||||
room_data_provider.own_user_id().to_owned(),
|
||||
room_data_provider.room_version(),
|
||||
internal_id_prefix,
|
||||
@@ -324,7 +328,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
let decryption_retry_task =
|
||||
DecryptionRetryTask::new(state.clone(), room_data_provider.clone());
|
||||
|
||||
Self { state, focus: focus_data, room_data_provider, settings, decryption_retry_task }
|
||||
Self { state, focus, room_data_provider, settings, decryption_retry_task }
|
||||
}
|
||||
|
||||
/// Initializes the configured focus with appropriate data.
|
||||
@@ -338,7 +342,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
room_event_cache: &RoomEventCache,
|
||||
) -> Result<bool, Error> {
|
||||
match &*self.focus {
|
||||
TimelineFocusData::Live { .. } => {
|
||||
TimelineFocusKind::Live { .. } => {
|
||||
// Retrieve the cached events, and add them to the timeline.
|
||||
let events = room_event_cache.events().await;
|
||||
|
||||
@@ -364,7 +368,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
Ok(has_events)
|
||||
}
|
||||
|
||||
TimelineFocusData::Event { event_id, paginator, num_context_events, .. } => {
|
||||
TimelineFocusKind::Event { event_id, paginator, num_context_events, .. } => {
|
||||
// Start a /context request, and append the results (in order) to the timeline.
|
||||
let start_from_result = paginator
|
||||
.start_from(event_id, (*num_context_events).into())
|
||||
@@ -382,7 +386,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
Ok(has_events)
|
||||
}
|
||||
|
||||
TimelineFocusData::Thread { loader, num_events, .. } => {
|
||||
TimelineFocusKind::Thread { loader, num_events, .. } => {
|
||||
let result = loader
|
||||
.paginate_backwards((*num_events).into())
|
||||
.await
|
||||
@@ -398,7 +402,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
TimelineFocusData::PinnedEvents { loader } => {
|
||||
TimelineFocusKind::PinnedEvents { loader } => {
|
||||
let Some(loaded_events) =
|
||||
loader.load_events().await.map_err(Error::PinnedEventsError)?
|
||||
else {
|
||||
@@ -453,7 +457,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
pub(crate) async fn reload_pinned_events(
|
||||
&self,
|
||||
) -> Result<Option<Vec<TimelineEvent>>, PinnedEventsLoaderError> {
|
||||
if let TimelineFocusData::PinnedEvents { loader } = &*self.focus {
|
||||
if let TimelineFocusKind::PinnedEvents { loader } = &*self.focus {
|
||||
loader.load_events().await
|
||||
} else {
|
||||
Err(PinnedEventsLoaderError::TimelineFocusNotPinnedEvents)
|
||||
@@ -490,14 +494,14 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
num_events: u16,
|
||||
) -> Result<bool, PaginationError> {
|
||||
let PaginationResult { events, hit_end_of_timeline } = match &*self.focus {
|
||||
TimelineFocusData::Live { .. } | TimelineFocusData::PinnedEvents { .. } => {
|
||||
TimelineFocusKind::Live { .. } | TimelineFocusKind::PinnedEvents { .. } => {
|
||||
return Err(PaginationError::NotSupported);
|
||||
}
|
||||
TimelineFocusData::Event { paginator, .. } => paginator
|
||||
TimelineFocusKind::Event { paginator, .. } => paginator
|
||||
.paginate_backward(num_events.into())
|
||||
.await
|
||||
.map_err(PaginationError::Paginator)?,
|
||||
TimelineFocusData::Thread { loader, num_events, .. } => loader
|
||||
TimelineFocusKind::Thread { loader, num_events, .. } => loader
|
||||
.paginate_backwards((*num_events).into())
|
||||
.await
|
||||
.map_err(PaginationError::Paginator)?,
|
||||
@@ -523,11 +527,11 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
num_events: u16,
|
||||
) -> Result<bool, PaginationError> {
|
||||
let PaginationResult { events, hit_end_of_timeline } = match &*self.focus {
|
||||
TimelineFocusData::Live { .. }
|
||||
| TimelineFocusData::PinnedEvents { .. }
|
||||
| TimelineFocusData::Thread { .. } => return Err(PaginationError::NotSupported),
|
||||
TimelineFocusKind::Live { .. }
|
||||
| TimelineFocusKind::PinnedEvents { .. }
|
||||
| TimelineFocusKind::Thread { .. } => return Err(PaginationError::NotSupported),
|
||||
|
||||
TimelineFocusData::Event { paginator, .. } => paginator
|
||||
TimelineFocusKind::Event { paginator, .. } => paginator
|
||||
.paginate_forward(num_events.into())
|
||||
.await
|
||||
.map_err(PaginationError::Paginator)?,
|
||||
@@ -546,7 +550,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
|
||||
|
||||
/// Is this timeline receiving events from sync (aka has a live focus)?
|
||||
pub(super) fn is_live(&self) -> bool {
|
||||
matches!(&*self.focus, TimelineFocusData::Live { .. })
|
||||
matches!(&*self.focus, TimelineFocusKind::Live { .. })
|
||||
}
|
||||
|
||||
pub(super) fn with_settings(mut self, settings: TimelineSettings) -> Self {
|
||||
|
||||
@@ -38,7 +38,7 @@ use super::{
|
||||
observable_items::ObservableItems,
|
||||
DateDividerMode, TimelineMetadata, TimelineSettings, TimelineStateTransaction,
|
||||
};
|
||||
use crate::{timeline::controller::TimelineFocusData, unable_to_decrypt_hook::UtdHookManager};
|
||||
use crate::{timeline::controller::TimelineFocusKind, unable_to_decrypt_hook::UtdHookManager};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(in crate::timeline) struct TimelineState<P: RoomDataProvider> {
|
||||
@@ -46,12 +46,12 @@ pub(in crate::timeline) struct TimelineState<P: RoomDataProvider> {
|
||||
pub meta: TimelineMetadata,
|
||||
|
||||
/// The kind of focus of this timeline.
|
||||
focus_data: Arc<TimelineFocusData<P>>,
|
||||
focus: Arc<TimelineFocusKind<P>>,
|
||||
}
|
||||
|
||||
impl<P: RoomDataProvider> TimelineState<P> {
|
||||
pub(super) fn new(
|
||||
focus_data: Arc<TimelineFocusData<P>>,
|
||||
focus: Arc<TimelineFocusKind<P>>,
|
||||
own_user_id: OwnedUserId,
|
||||
room_version: RoomVersionId,
|
||||
internal_id_prefix: Option<String>,
|
||||
@@ -67,7 +67,7 @@ impl<P: RoomDataProvider> TimelineState<P> {
|
||||
unable_to_decrypt_hook,
|
||||
is_room_encrypted,
|
||||
),
|
||||
focus_data,
|
||||
focus,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,13 +164,13 @@ impl<P: RoomDataProvider> TimelineState<P> {
|
||||
|
||||
// TODO merge with other should_add, one way or another?
|
||||
let should_add_new_items = match &txn.focus {
|
||||
TimelineFocusData::Live { hide_threaded_events } => {
|
||||
TimelineFocusKind::Live { hide_threaded_events } => {
|
||||
thread_root.is_none() || !hide_threaded_events
|
||||
}
|
||||
TimelineFocusData::Thread { root_event_id, .. } => {
|
||||
TimelineFocusKind::Thread { root_event_id, .. } => {
|
||||
thread_root.as_ref().is_some_and(|r| r == root_event_id)
|
||||
}
|
||||
TimelineFocusData::Event { .. } | TimelineFocusData::PinnedEvents { .. } => {
|
||||
TimelineFocusKind::Event { .. } | TimelineFocusKind::PinnedEvents { .. } => {
|
||||
// Don't add new items to these timelines; aggregations are added independently
|
||||
// of the `should_add_new_items` value.
|
||||
false
|
||||
@@ -299,6 +299,6 @@ impl<P: RoomDataProvider> TimelineState<P> {
|
||||
}
|
||||
|
||||
pub(super) fn transaction(&mut self) -> TimelineStateTransaction<'_, P> {
|
||||
TimelineStateTransaction::new(&mut self.items, &mut self.meta, &*self.focus_data)
|
||||
TimelineStateTransaction::new(&mut self.items, &mut self.meta, &*self.focus)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ use super::{
|
||||
ObservableItems, ObservableItemsTransaction, TimelineMetadata, TimelineSettings,
|
||||
};
|
||||
use crate::timeline::{
|
||||
controller::TimelineFocusData,
|
||||
controller::TimelineFocusKind,
|
||||
event_handler::{FailedToParseEvent, RemovedItem, TimelineAction},
|
||||
EmbeddedEvent, ThreadSummary, TimelineDetails, VirtualTimelineItem,
|
||||
};
|
||||
@@ -59,7 +59,7 @@ pub(in crate::timeline) struct TimelineStateTransaction<'a, P: RoomDataProvider>
|
||||
previous_meta: &'a mut TimelineMetadata,
|
||||
|
||||
/// The kind of focus of this timeline.
|
||||
pub focus: &'a TimelineFocusData<P>,
|
||||
pub focus: &'a TimelineFocusKind<P>,
|
||||
}
|
||||
|
||||
impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
|
||||
@@ -67,7 +67,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
|
||||
pub(super) fn new(
|
||||
items: &'a mut ObservableItems,
|
||||
meta: &'a mut TimelineMetadata,
|
||||
focus: &'a TimelineFocusData<P>,
|
||||
focus: &'a TimelineFocusKind<P>,
|
||||
) -> Self {
|
||||
let previous_meta = meta;
|
||||
let meta = previous_meta.clone();
|
||||
@@ -403,12 +403,12 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
|
||||
}
|
||||
|
||||
match &self.focus {
|
||||
TimelineFocusData::PinnedEvents { .. } => {
|
||||
TimelineFocusKind::PinnedEvents { .. } => {
|
||||
// Only add pinned events for the pinned events timeline.
|
||||
room_data_provider.is_pinned_event(event.event_id())
|
||||
}
|
||||
|
||||
TimelineFocusData::Event { hide_threaded_events, .. } => {
|
||||
TimelineFocusKind::Event { hide_threaded_events, .. } => {
|
||||
// If the timeline's filtering out in-thread events, don't add items for
|
||||
// threaded events.
|
||||
if thread_root.is_some() && *hide_threaded_events {
|
||||
@@ -435,13 +435,13 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
|
||||
}
|
||||
}
|
||||
|
||||
TimelineFocusData::Live { hide_threaded_events } => {
|
||||
TimelineFocusKind::Live { hide_threaded_events } => {
|
||||
// If the timeline's filtering out in-thread events, don't add items for
|
||||
// threaded events.
|
||||
thread_root.is_none() || !hide_threaded_events
|
||||
}
|
||||
|
||||
TimelineFocusData::Thread { root_event_id, .. } => {
|
||||
TimelineFocusKind::Thread { root_event_id, .. } => {
|
||||
// Add new items only for the thread root and the thread replies.
|
||||
event.event_id() == root_event_id
|
||||
|| thread_root.as_ref().is_some_and(|r| r == root_event_id)
|
||||
|
||||
@@ -109,7 +109,7 @@ impl Stream for TimelineSubscriber {
|
||||
pub mod skip {
|
||||
use eyeball::{SharedObservable, Subscriber};
|
||||
|
||||
use crate::timeline::{controller::TimelineFocusData, traits::RoomDataProvider};
|
||||
use crate::timeline::{controller::TimelineFocusKind, traits::RoomDataProvider};
|
||||
|
||||
const MAXIMUM_NUMBER_OF_INITIAL_ITEMS: usize = 20;
|
||||
|
||||
@@ -248,8 +248,8 @@ pub mod skip {
|
||||
|
||||
/// Update the skip count if and only if the timeline has a live focus
|
||||
/// ([`TimelineFocusKind::Live`]).
|
||||
pub fn update<P: RoomDataProvider>(&self, count: usize, focus: &TimelineFocusData<P>) {
|
||||
if matches!(focus, TimelineFocusData::Live { .. }) {
|
||||
pub fn update<P: RoomDataProvider>(&self, count: usize, focus: &TimelineFocusKind<P>) {
|
||||
if matches!(focus, TimelineFocusKind::Live { .. }) {
|
||||
self.count.set_if_not_eq(count);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user