@@ -37,7 +37,6 @@ pub struct CallInfo {
37
37
38
38
/// Was an incoming call accepted on this device?
39
39
/// On other devices, this is never set and for outgoing calls, this is never set.
40
- /// Internally, this is written to Param::Arg.
41
40
pub accepted : bool ,
42
41
43
42
/// Info message referring to the call.
@@ -234,18 +233,30 @@ impl Context {
234
233
235
234
Ok ( CallInfo {
236
235
incoming : call. get_info_type ( ) == SystemMessage :: IncomingCall ,
237
- accepted : call. param . get_int ( Param :: Arg ) == Some ( 1 ) ,
236
+ accepted : call. is_call_accepted ( ) ? ,
238
237
msg : call,
239
238
} )
240
239
}
241
240
}
242
241
243
242
impl Message {
244
243
async fn mark_call_as_accepted ( & mut self , context : & Context ) -> Result < ( ) > {
244
+ ensure ! (
245
+ self . get_info_type( ) == SystemMessage :: IncomingCall
246
+ || self . get_info_type( ) == SystemMessage :: OutgoingCall
247
+ ) ;
245
248
self . param . set_int ( Param :: Arg , 1 ) ;
246
249
self . update_param ( context) . await ?;
247
250
Ok ( ( ) )
248
251
}
252
+
253
+ fn is_call_accepted ( & self ) -> Result < bool > {
254
+ ensure ! (
255
+ self . get_info_type( ) == SystemMessage :: IncomingCall
256
+ || self . get_info_type( ) == SystemMessage :: OutgoingCall
257
+ ) ;
258
+ Ok ( self . param . get_int ( Param :: Arg ) == Some ( 1 ) )
259
+ }
249
260
}
250
261
251
262
#[ cfg( test) ]
@@ -504,4 +515,20 @@ mod tests {
504
515
505
516
Ok ( ( ) )
506
517
}
518
+
519
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
520
+ async fn test_mark_call_as_accepted ( ) -> Result < ( ) > {
521
+ let ( alice, _alice2, alice_call, _bob, _bob2, _bob_call, _bob2_call) = setup_call ( ) . await ?;
522
+ assert ! ( !alice_call. is_call_accepted( ) ?) ;
523
+
524
+ let mut alice_call = Message :: load_from_db ( & alice, alice_call. id ) . await ?;
525
+ assert ! ( !alice_call. is_call_accepted( ) ?) ;
526
+ alice_call. mark_call_as_accepted ( & alice) . await ?;
527
+ assert ! ( alice_call. is_call_accepted( ) ?) ;
528
+
529
+ let alice_call = Message :: load_from_db ( & alice, alice_call. id ) . await ?;
530
+ assert ! ( alice_call. is_call_accepted( ) ?) ;
531
+
532
+ Ok ( ( ) )
533
+ }
507
534
}
0 commit comments