14
14
15
15
//! No I/O logic of the [`WidgetDriver`].
16
16
17
- use std:: { iter , time:: Duration } ;
17
+ use std:: time:: Duration ;
18
18
19
19
use driver_req:: UpdateDelayedEventRequest ;
20
20
use from_widget:: UpdateDelayedEventResponse ;
@@ -248,7 +248,10 @@ impl WidgetMachine {
248
248
. unwrap_or_default ( ) ,
249
249
250
250
FromWidgetRequest :: GetOpenId { } => {
251
- let request_action = self . send_matrix_driver_request ( RequestOpenId ) . map (
251
+ let mut actions =
252
+ vec ! [ Self :: send_from_widget_response( raw_request, Ok ( OpenIdResponse :: Pending ) ) ] ;
253
+
254
+ if let Some ( request_action) = self . send_matrix_driver_request ( RequestOpenId ) . map (
252
255
|( request, request_action) | {
253
256
request. then ( |res, machine| {
254
257
let response = match res {
@@ -269,11 +272,11 @@ impl WidgetMachine {
269
272
270
273
request_action
271
274
} ,
272
- ) ;
275
+ ) {
276
+ actions. push ( request_action) ;
277
+ }
273
278
274
- let response =
275
- Self :: send_from_widget_response ( raw_request, Ok ( OpenIdResponse :: Pending ) ) ;
276
- iter:: once ( response) . chain ( request_action) . collect ( )
279
+ actions
277
280
}
278
281
279
282
FromWidgetRequest :: DelayedEventUpdate ( req) => {
@@ -613,11 +616,15 @@ impl WidgetMachine {
613
616
}
614
617
615
618
fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
616
- let unsubscribe_required =
617
- matches ! ( & self . capabilities, CapabilitiesState :: Negotiated ( c) if !c. read. is_empty( ) ) ;
619
+ let mut actions = Vec :: new ( ) ;
620
+
621
+ if matches ! ( & self . capabilities, CapabilitiesState :: Negotiated ( c) if !c. read. is_empty( ) ) {
622
+ actions. push ( Action :: Unsubscribe ) ;
623
+ }
624
+
618
625
self . capabilities = CapabilitiesState :: Negotiating ;
619
626
620
- let action =
627
+ if let Some ( action) =
621
628
self . send_to_widget_request ( RequestCapabilities { } ) . map ( |( request, action) | {
622
629
request. then ( |response, machine| {
623
630
let requested_capabilities = response. capabilities ;
@@ -633,7 +640,11 @@ impl WidgetMachine {
633
640
Capabilities :: default ( )
634
641
} ) ;
635
642
636
- let subscribe_required = !approved_capabilities. read . is_empty ( ) ;
643
+ let mut actions = Vec :: new ( ) ;
644
+ if !approved_capabilities. read . is_empty ( ) {
645
+ actions. push ( Action :: Subscribe ) ;
646
+ }
647
+
637
648
machine. capabilities =
638
649
CapabilitiesState :: Negotiated ( approved_capabilities. clone ( ) ) ;
639
650
@@ -642,15 +653,14 @@ impl WidgetMachine {
642
653
requested : requested_capabilities,
643
654
} ;
644
655
645
- let action = machine
656
+ if let Some ( action) = machine
646
657
. send_to_widget_request ( notify_caps_changed)
647
- . map ( |( _request, action) | action) ;
658
+ . map ( |( _request, action) | action)
659
+ {
660
+ actions. push ( action) ;
661
+ }
648
662
649
- subscribe_required
650
- . then_some ( Action :: Subscribe )
651
- . into_iter ( )
652
- . chain ( action)
653
- . collect ( )
663
+ actions
654
664
} ) ;
655
665
656
666
vec ! [ action]
@@ -660,9 +670,12 @@ impl WidgetMachine {
660
670
} ) ;
661
671
662
672
action
663
- } ) ;
673
+ } )
674
+ {
675
+ actions. push ( action) ;
676
+ }
664
677
665
- unsubscribe_required . then_some ( Action :: Unsubscribe ) . into_iter ( ) . chain ( action ) . collect ( )
678
+ actions
666
679
}
667
680
}
668
681
0 commit comments