refactor(timeline): remove generic from a few function signatures by using plain bools

This commit is contained in:
Benjamin Bouvier
2025-07-01 11:34:43 +02:00
parent 8b4a01ea54
commit 9ade32fcd0
5 changed files with 23 additions and 23 deletions

View File

@@ -38,12 +38,10 @@ use super::{
};
use crate::{
timeline::{
controller::TimelineFocusKind,
event_item::{
extract_bundled_edit_event_json, extract_poll_edit_content,
extract_room_msg_edit_content,
},
traits::RoomDataProvider,
InReplyToDetails, TimelineEventItemId,
},
unable_to_decrypt_hook::UtdHookManager,
@@ -312,13 +310,13 @@ impl TimelineMetadata {
/// Extract the content from a remote message-like event and process its
/// relations.
pub(crate) fn process_event_relations<P: RoomDataProvider>(
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>>,
timeline_focus: &TimelineFocusKind<P>,
is_thread_focus: bool,
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
if let AnySyncTimelineEvent::MessageLike(ev) = event {
if let Some(content) = ev.original_content() {
@@ -332,7 +330,7 @@ impl TimelineMetadata {
&content,
remote_ctx,
timeline_items,
timeline_focus,
is_thread_focus,
);
}
}
@@ -344,19 +342,19 @@ impl TimelineMetadata {
/// (like marking responses).
///
/// Returns the in-reply-to details and the thread root event ID, if any.
pub(crate) fn process_content_relations<P: RoomDataProvider>(
pub(crate) fn process_content_relations(
&mut self,
content: &AnyMessageLikeEventContent,
remote_ctx: Option<RemoteEventContext<'_>>,
timeline_items: &Vector<Arc<TimelineItem>>,
timeline_focus: &TimelineFocusKind<P>,
is_thread_focus: bool,
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
match content {
AnyMessageLikeEventContent::Sticker(content) => {
let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root(
content.relates_to.clone().and_then(|rel| rel.try_into().ok()),
timeline_items,
timeline_focus,
is_thread_focus,
);
if let Some(event_id) = remote_ctx.map(|ctx| ctx.event_id) {
@@ -372,7 +370,7 @@ impl TimelineMetadata {
let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root(
c.relates_to.clone(),
timeline_items,
timeline_focus,
is_thread_focus,
);
// Record the bundled edit in the aggregations set, if any.
@@ -410,7 +408,7 @@ impl TimelineMetadata {
let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root(
msg.relates_to.clone().and_then(|rel| rel.try_into().ok()),
timeline_items,
timeline_focus,
is_thread_focus,
);
// Record the bundled edit in the aggregations set, if any.
@@ -450,10 +448,10 @@ impl TimelineMetadata {
/// Extracts the in-reply-to details and thread root from a relation, if
/// available.
fn extract_reply_and_thread_root<P: RoomDataProvider>(
fn extract_reply_and_thread_root(
relates_to: Option<RelationWithoutReplacement>,
timeline_items: &Vector<Arc<TimelineItem>>,
timeline_focus: &TimelineFocusKind<P>,
is_thread_focus: bool,
) -> (Option<InReplyToDetails>, Option<OwnedEventId>) {
let mut thread_root = None;
@@ -464,9 +462,7 @@ impl TimelineMetadata {
RelationWithoutReplacement::Thread(thread) => {
thread_root = Some(thread.event_id);
if matches!(timeline_focus, TimelineFocusKind::Thread { .. })
&& thread.is_falling_back
{
if is_thread_focus && thread.is_falling_back {
// In general, a threaded event is marked as a response to the previous message
// in the thread, to maintain backwards compatibility with clients not
// supporting threads.

View File

@@ -285,6 +285,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
TimelineFocus::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());
TimelineFocusKind::Event {
@@ -480,7 +481,9 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
.subscriber_skip_count
.compute_next_when_paginating_backwards(num_events.into());
state.meta.subscriber_skip_count.update(count, &self.focus);
// This always happens on a live timeline.
let is_live_timeline = true;
state.meta.subscriber_skip_count.update(count, is_live_timeline);
needs
}

View File

@@ -159,8 +159,9 @@ impl<P: RoomDataProvider> TimelineState<P> {
let mut date_divider_adjuster = DateDividerAdjuster::new(date_divider_mode);
let is_thread_focus = matches!(txn.focus, TimelineFocusKind::Thread { .. });
let (in_reply_to, thread_root) =
txn.meta.process_content_relations(&content, None, &txn.items, txn.focus);
txn.meta.process_content_relations(&content, None, &txn.items, is_thread_focus);
// TODO merge with other should_add, one way or another?
let should_add_new_items = match &txn.focus {

View File

@@ -625,7 +625,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
&raw,
bundled_edit_encryption_info,
&self.items,
self.focus,
matches!(self.focus, TimelineFocusKind::Thread { .. }),
);
let should_add = self.should_add_event_item(
@@ -808,7 +808,9 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
.meta
.subscriber_skip_count
.compute_next(previous_number_of_items, next_number_of_items);
self.meta.subscriber_skip_count.update(count, self.focus);
self.meta
.subscriber_skip_count
.update(count, matches!(self.focus, TimelineFocusKind::Live { .. }));
}
// Replace the pointer to the previous meta with the new one.

View File

@@ -109,8 +109,6 @@ impl Stream for TimelineSubscriber {
pub mod skip {
use eyeball::{SharedObservable, Subscriber};
use crate::timeline::{controller::TimelineFocusKind, traits::RoomDataProvider};
const MAXIMUM_NUMBER_OF_INITIAL_ITEMS: usize = 20;
/// `SkipCount` helps to manage the `count` value used by the [`Skip`]
@@ -248,8 +246,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: &TimelineFocusKind<P>) {
if matches!(focus, TimelineFocusKind::Live { .. }) {
pub fn update(&self, count: usize, is_live_focus: bool) {
if is_live_focus {
self.count.set_if_not_eq(count);
}
}