ui: Split non-items fields of TimelineInnerState into separate struct

… as a preparation for further refactorings.
This commit is contained in:
Jonas Platte
2023-09-11 12:43:42 +02:00
committed by Jonas Platte
parent 7168df8b30
commit c6fd3ec4b0
3 changed files with 68 additions and 41 deletions

View File

@@ -596,7 +596,7 @@ impl<'a> TimelineEventHandler<'a> {
_ => None,
},
not_found: || {
self.state.poll_pending_events.add_response(
self.state.meta.poll_pending_events.add_response(
&c.relates_to.event_id,
&self.ctx.sender,
self.ctx.timestamp,
@@ -623,7 +623,7 @@ impl<'a> TimelineEventHandler<'a> {
_ => None,
},
not_found: || {
self.state.poll_pending_events.add_end(&c.relates_to.event_id, self.ctx.timestamp);
self.state.meta.poll_pending_events.add_end(&c.relates_to.event_id, self.ctx.timestamp);
}
);
}
@@ -705,7 +705,7 @@ impl<'a> TimelineEventHandler<'a> {
return None;
}
Some(event_item.redact(&self.state.room_version))
Some(event_item.redact(&self.state.meta.room_version))
});
if self.result.items_updated == 0 {
@@ -719,7 +719,7 @@ impl<'a> TimelineEventHandler<'a> {
let Some(in_reply_to) = message.in_reply_to() else { return };
let TimelineDetails::Ready(replied_to_event) = &in_reply_to.event else { return };
if redacts == in_reply_to.event_id {
let replied_to_event = replied_to_event.redact(&self.state.room_version);
let replied_to_event = replied_to_event.redact(&self.state.meta.room_version);
let in_reply_to = InReplyToDetails {
event_id: in_reply_to.event_id.clone(),
event: TimelineDetails::Ready(Box::new(replied_to_event)),
@@ -900,7 +900,7 @@ impl<'a> TimelineEventHandler<'a> {
&mut item,
self.ctx.is_own_event,
&mut self.state.items,
&mut self.state.users_read_receipts,
&mut self.state.meta.users_read_receipts,
);
}
@@ -954,7 +954,7 @@ impl<'a> TimelineEventHandler<'a> {
&mut item,
self.ctx.is_own_event,
&mut self.state.items,
&mut self.state.users_read_receipts,
&mut self.state.meta.users_read_receipts,
);
}
@@ -1071,7 +1071,7 @@ impl<'a> TimelineEventHandler<'a> {
&mut item,
self.ctx.is_own_event,
&mut self.state.items,
&mut self.state.users_read_receipts,
&mut self.state.meta.users_read_receipts,
);
}
@@ -1104,8 +1104,8 @@ impl<'a> TimelineEventHandler<'a> {
if self.state.event_should_update_fully_read_marker {
update_read_marker(
&mut self.state.items,
self.state.fully_read_event.as_deref(),
&mut self.state.event_should_update_fully_read_marker,
self.state.meta.fully_read_event.as_deref(),
&mut self.state.meta.event_should_update_fully_read_marker,
);
}
}

View File

@@ -100,24 +100,7 @@ impl fmt::Debug for TimelineInnerStateLock {
#[derive(Debug)]
pub(in crate::timeline) struct TimelineInnerState {
pub items: ObservableVector<Arc<TimelineItem>>,
next_internal_id: u64,
pub reactions: Reactions,
pub poll_pending_events: PollPendingEvents,
pub fully_read_event: Option<OwnedEventId>,
/// Whether the fully-read marker item should try to be updated when an
/// event is added.
/// This is currently `true` in two cases:
/// - The fully-read marker points to an event that is not in the timeline,
/// - The fully-read marker item would be the last item in the timeline.
pub event_should_update_fully_read_marker: bool,
/// User ID => Receipt type => Read receipt of the user of the given
/// type.
pub users_read_receipts: HashMap<OwnedUserId, HashMap<ReceiptType, (OwnedEventId, Receipt)>>,
/// the local reaction request state that is queued next
pub reaction_state: IndexMap<AnnotationKey, ReactionState>,
/// the in flight reaction request state that is ongoing
pub in_flight_reaction: IndexMap<AnnotationKey, ReactionState>,
pub room_version: RoomVersionId,
pub meta: TimelineInnerMetadata,
}
impl TimelineInnerState {
@@ -127,15 +110,7 @@ impl TimelineInnerState {
// sliding-sync tests with 20 events lag. This should still be
// small enough.
items: ObservableVector::with_capacity(32),
next_internal_id: Default::default(),
reactions: Default::default(),
poll_pending_events: Default::default(),
fully_read_event: Default::default(),
event_should_update_fully_read_marker: Default::default(),
users_read_receipts: Default::default(),
reaction_state: Default::default(),
in_flight_reaction: Default::default(),
room_version,
meta: TimelineInnerMetadata::new(room_version),
}
}
@@ -378,8 +353,8 @@ impl TimelineInnerState {
update_read_marker(
&mut self.items,
self.fully_read_event.as_deref(),
&mut self.event_should_update_fully_read_marker,
self.meta.fully_read_event.as_deref(),
&mut self.meta.event_should_update_fully_read_marker,
);
}
@@ -459,7 +434,7 @@ impl TimelineInnerState {
// (should the local echo already be up-to-date after event handling?)
if let Some(txn_id) = local_echo_to_remove {
let id = EventItemIdentifier::TransactionId(txn_id.clone());
if self.reactions.map.remove(&id).is_none() {
if self.meta.reactions.map.remove(&id).is_none() {
warn!(
"Tried to remove reaction by transaction ID, but didn't \
find matching reaction in the reaction map"
@@ -468,7 +443,7 @@ impl TimelineInnerState {
}
// Add the remote echo to the reaction_map
if let Some(event_id) = remote_echo_to_add {
self.reactions.map.insert(
self.meta.reactions.map.insert(
EventItemIdentifier::EventId(event_id.clone()),
(reaction_sender_data, annotation.clone()),
);
@@ -481,6 +456,58 @@ impl TimelineInnerState {
}
}
impl Deref for TimelineInnerState {
type Target = TimelineInnerMetadata;
fn deref(&self) -> &Self::Target {
&self.meta
}
}
impl DerefMut for TimelineInnerState {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.meta
}
}
#[derive(Debug)]
pub(in crate::timeline) struct TimelineInnerMetadata {
next_internal_id: u64,
pub reactions: Reactions,
pub poll_pending_events: PollPendingEvents,
pub fully_read_event: Option<OwnedEventId>,
/// Whether the fully-read marker item should try to be updated when an
/// event is added.
/// This is currently `true` in two cases:
/// - The fully-read marker points to an event that is not in the timeline,
/// - The fully-read marker item would be the last item in the timeline.
pub event_should_update_fully_read_marker: bool,
/// User ID => Receipt type => Read receipt of the user of the given
/// type.
pub users_read_receipts: HashMap<OwnedUserId, HashMap<ReceiptType, (OwnedEventId, Receipt)>>,
/// the local reaction request state that is queued next
pub reaction_state: IndexMap<AnnotationKey, ReactionState>,
/// the in flight reaction request state that is ongoing
pub in_flight_reaction: IndexMap<AnnotationKey, ReactionState>,
pub room_version: RoomVersionId,
}
impl TimelineInnerMetadata {
fn new(room_version: RoomVersionId) -> TimelineInnerMetadata {
Self {
next_internal_id: Default::default(),
reactions: Default::default(),
poll_pending_events: Default::default(),
fully_read_event: Default::default(),
event_should_update_fully_read_marker: Default::default(),
users_read_receipts: Default::default(),
reaction_state: Default::default(),
in_flight_reaction: Default::default(),
room_version,
}
}
}
pub(in crate::timeline) struct TimelineInnerStateWriteGuard<'a> {
inner: RwLockWriteGuard<'a, TimelineInnerState>,
lock_release_ob: SharedObservable<()>,

View File

@@ -87,7 +87,7 @@ impl TimelineInnerState {
receipt_item_pos,
is_own_user_id,
&mut self.items,
&mut self.users_read_receipts,
&mut self.meta.users_read_receipts,
);
if read_receipt_updated && !is_own_user_id {