Skip to content

Commit 182e84c

Browse files
committed
timeline: get rid of deref/deref_mut from TimelineInnerState to TimelineInnerMetadata
1 parent 5c049d6 commit 182e84c

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

crates/matrix-sdk-ui/src/timeline/inner/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ impl<P: RoomDataProvider> TimelineInner<P> {
299299
(None, None) => {
300300
// No record of the reaction, create a local echo
301301

302-
let in_flight = state.in_flight_reaction.get::<AnnotationKey>(&annotation.into());
302+
let in_flight =
303+
state.meta.in_flight_reaction.get::<AnnotationKey>(&annotation.into());
303304
let txn_id = match in_flight {
304305
Some(ReactionState::Sending(txn_id)) => {
305306
// Use the transaction ID as the in flight request
@@ -343,10 +344,10 @@ impl<P: RoomDataProvider> TimelineInner<P> {
343344
}
344345
};
345346

346-
state.reaction_state.insert(annotation.into(), reaction_state.clone());
347+
state.meta.reaction_state.insert(annotation.into(), reaction_state.clone());
347348

348349
// Check the action to perform depending on any in flight request
349-
let in_flight = state.in_flight_reaction.get::<AnnotationKey>(&annotation.into());
350+
let in_flight = state.meta.in_flight_reaction.get::<AnnotationKey>(&annotation.into());
350351
let result = match in_flight {
351352
Some(_) => {
352353
// There is an in-flight request
@@ -371,7 +372,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
371372
ReactionAction::None => {}
372373
ReactionAction::SendRemote(_) | ReactionAction::RedactRemote(_) => {
373374
// Remember the new in flight request
374-
state.in_flight_reaction.insert(annotation.into(), reaction_state);
375+
state.meta.in_flight_reaction.insert(annotation.into(), reaction_state);
375376
}
376377
};
377378

@@ -397,7 +398,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
397398
}
398399

399400
if let Some(read_receipt) = read_receipt {
400-
self.state.write().await.read_receipts.upsert_latest(
401+
self.state.write().await.meta.read_receipts.upsert_latest(
401402
own_user_id,
402403
receipt_type,
403404
read_receipt,
@@ -602,6 +603,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
602603
let annotation_key: AnnotationKey = annotation.into();
603604

604605
let reaction_state = state
606+
.meta
605607
.reaction_state
606608
.get(&AnnotationKey::from(annotation))
607609
.expect("Reaction state should be set before sending the reaction");
@@ -610,6 +612,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
610612
(ReactionToggleResult::AddSuccess { event_id, .. }, ReactionState::Redacting(_)) => {
611613
// A reaction was added successfully but we've been requested to undo it
612614
state
615+
.meta
613616
.in_flight_reaction
614617
.insert(annotation_key, ReactionState::Redacting(Some(event_id.to_owned())));
615618
ReactionAction::RedactRemote(event_id.to_owned())
@@ -618,14 +621,15 @@ impl<P: RoomDataProvider> TimelineInner<P> {
618621
// A reaction was was redacted successfully but we've been requested to undo it
619622
let txn_id = txn_id.to_owned();
620623
state
624+
.meta
621625
.in_flight_reaction
622626
.insert(annotation_key, ReactionState::Sending(txn_id.clone()));
623627
ReactionAction::SendRemote(txn_id)
624628
}
625629
_ => {
626630
// We're done, so also update the timeline
627-
state.in_flight_reaction.swap_remove(&annotation_key);
628-
state.reaction_state.swap_remove(&annotation_key);
631+
state.meta.in_flight_reaction.swap_remove(&annotation_key);
632+
state.meta.reaction_state.swap_remove(&annotation_key);
629633
state.update_timeline_reaction(user_id, annotation, result)?;
630634

631635
ReactionAction::None
@@ -756,7 +760,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
756760
let settings = self.settings.clone();
757761
let room_data_provider = self.room_data_provider.clone();
758762
let push_rules_context = room_data_provider.push_rules_and_context().await;
759-
let unable_to_decrypt_hook = state.unable_to_decrypt_hook.clone();
763+
let unable_to_decrypt_hook = state.meta.unable_to_decrypt_hook.clone();
760764

761765
matrix_sdk::executor::spawn(async move {
762766
let retry_one = |item: Arc<TimelineItem>| {
@@ -1080,7 +1084,7 @@ impl TimelineInner {
10801084
match receipt_type {
10811085
SendReceiptType::Read => {
10821086
if let Some((old_pub_read, _)) =
1083-
state.user_receipt(own_user_id, ReceiptType::Read, room).await
1087+
state.meta.user_receipt(own_user_id, ReceiptType::Read, room).await
10841088
{
10851089
trace!(%old_pub_read, "found a previous public receipt");
10861090
if let Some(relative_pos) =
@@ -1127,7 +1131,7 @@ impl TimelineInner {
11271131
/// it's folded into another timeline item.
11281132
pub(crate) async fn latest_event_id(&self) -> Option<OwnedEventId> {
11291133
let state = self.state.read().await;
1130-
state.all_events.back().map(|event_meta| &event_meta.event_id).cloned()
1134+
state.meta.all_events.back().map(|event_meta| &event_meta.event_id).cloned()
11311135
}
11321136
}
11331137

@@ -1169,7 +1173,7 @@ async fn fetch_replied_to_event(
11691173
});
11701174
let event_item = item.with_content(TimelineItemContent::Message(reply), None);
11711175

1172-
let new_timeline_item = state.new_timeline_item(event_item);
1176+
let new_timeline_item = state.meta.new_timeline_item(event_item);
11731177
state.items.set(index, new_timeline_item);
11741178

11751179
// Don't hold the state lock while the network request is made

crates/matrix-sdk-ui/src/timeline/inner/state.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::{
1616
collections::VecDeque,
1717
future::Future,
1818
mem::{self, ManuallyDrop},
19-
ops::{Deref, DerefMut},
2019
sync::Arc,
2120
};
2221

@@ -410,20 +409,6 @@ impl TimelineInnerState {
410409
}
411410
}
412411

413-
impl Deref for TimelineInnerState {
414-
type Target = TimelineInnerMetadata;
415-
416-
fn deref(&self) -> &Self::Target {
417-
&self.meta
418-
}
419-
}
420-
421-
impl DerefMut for TimelineInnerState {
422-
fn deref_mut(&mut self) -> &mut Self::Target {
423-
&mut self.meta
424-
}
425-
}
426-
427412
pub(in crate::timeline) struct TimelineInnerStateTransaction<'a> {
428413
pub items: ManuallyDrop<ObservableVectorTransaction<'a, Arc<TimelineItem>>>,
429414

crates/matrix-sdk-ui/src/timeline/read_receipts.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,15 @@ impl TimelineInnerState {
505505
room_data_provider: &P,
506506
) -> Option<(OwnedEventId, Receipt)> {
507507
let public_read_receipt =
508-
self.user_receipt(user_id, ReceiptType::Read, room_data_provider).await;
508+
self.meta.user_receipt(user_id, ReceiptType::Read, room_data_provider).await;
509509
let private_read_receipt =
510-
self.user_receipt(user_id, ReceiptType::ReadPrivate, room_data_provider).await;
510+
self.meta.user_receipt(user_id, ReceiptType::ReadPrivate, room_data_provider).await;
511511

512512
// Let's assume that a private read receipt should be more recent than a public
513513
// read receipt, otherwise there's no point in the private read receipt,
514514
// and use it as default.
515515
match self
516+
.meta
516517
.compare_optional_receipts(public_read_receipt.as_ref(), private_read_receipt.as_ref())
517518
{
518519
Ordering::Greater => public_read_receipt,
@@ -529,22 +530,23 @@ impl TimelineInnerState {
529530
) -> Option<OwnedEventId> {
530531
// We only need to use the local map, since receipts for known events are
531532
// already loaded from the store.
532-
let public_read_receipt = self.read_receipts.get_latest(user_id, &ReceiptType::Read);
533+
let public_read_receipt = self.meta.read_receipts.get_latest(user_id, &ReceiptType::Read);
533534
let private_read_receipt =
534-
self.read_receipts.get_latest(user_id, &ReceiptType::ReadPrivate);
535+
self.meta.read_receipts.get_latest(user_id, &ReceiptType::ReadPrivate);
535536

536537
// Let's assume that a private read receipt should be more recent than a public
537538
// read receipt, otherwise there's no point in the private read receipt,
538539
// and use it as default.
539540
let (latest_receipt_id, _) =
540-
match self.compare_optional_receipts(public_read_receipt, private_read_receipt) {
541+
match self.meta.compare_optional_receipts(public_read_receipt, private_read_receipt) {
541542
Ordering::Greater => public_read_receipt?,
542543
Ordering::Less => private_read_receipt?,
543544
_ => unreachable!(),
544545
};
545546

546547
// Find the corresponding visible event.
547-
self.all_events
548+
self.meta
549+
.all_events
548550
.iter()
549551
.rev()
550552
.skip_while(|ev| ev.event_id != *latest_receipt_id)

0 commit comments

Comments
 (0)