Skip to content

Commit 6f507ed

Browse files
committed
refactor(widget): Use clearer types for processing read state response
1 parent 8c9900e commit 6f507ed

File tree

1 file changed

+14
-10
lines changed
  • crates/matrix-sdk/src/widget/machine

1 file changed

+14
-10
lines changed

crates/matrix-sdk/src/widget/machine/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -660,29 +660,26 @@ impl WidgetMachine {
660660
/// [`NotifyStateUpdate`] action.
661661
fn process_read_initial_state_response(
662662
&mut self,
663-
events: Result<Vec<Raw<AnyStateEvent>>, Error>,
664-
) -> Vec<Action> {
663+
events: Vec<Raw<AnyStateEvent>>,
664+
) -> Option<Vec<Action>> {
665665
// Pull the updates struct out of the machine temporarily so that we can match
666666
// on it in one place, mutate it, and still be able to call
667667
// `send_to_widget_request` later in this block (which borrows the machine
668668
// mutably)
669669
match self.pending_state_updates.take() {
670670
None => {
671671
error!("Initial state updates must only be set to `None` once all requests are complete; dropping state response");
672-
Vec::new()
672+
None
673673
}
674674

675675
Some(mut updates) => {
676-
updates.initial_state.push(events.unwrap_or_else(|e| {
677-
error!("Reading initial room state failed: {e}");
678-
Vec::new()
679-
}));
676+
updates.initial_state.push(events);
680677

681678
if updates.initial_state.len() != updates.request_count {
682679
// Not all of the initial state requests have completed yet; put the updates
683680
// struct back so we can continue accumulating the initial state.
684681
self.pending_state_updates = Some(updates);
685-
return Vec::new();
682+
return None;
686683
}
687684

688685
// The initial state is complete; combine the data and push it to the widget in
@@ -701,7 +698,7 @@ impl WidgetMachine {
701698
.map(|state| self.send_state_update(state));
702699

703700
// The postponed updates should come after the initial update
704-
initial.into_iter().chain(postponed.flatten()).collect()
701+
Some(initial.into_iter().chain(postponed.flatten()).collect())
705702
}
706703
}
707704
}
@@ -771,7 +768,14 @@ impl WidgetMachine {
771768
})
772769
.map(|(request, action)| {
773770
request.add_response_handler(move |result, machine| {
774-
machine.process_read_initial_state_response(result)
771+
machine
772+
.process_read_initial_state_response(result.unwrap_or_else(|e| {
773+
error!("Reading initial room state failed: {e}");
774+
// Pretend that we just got an empty response so the initial state
775+
// update won't be completely blocked on this one bit of missing data
776+
Vec::new()
777+
}))
778+
.unwrap_or_default()
775779
});
776780
action
777781
})

0 commit comments

Comments
 (0)