@@ -3712,19 +3712,64 @@ async fn test_receive_edit_request_after_removal() -> Result<()> {
3712
3712
}
3713
3713
3714
3714
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
3715
- async fn test_cannot_edit_html ( ) -> Result < ( ) > {
3715
+ async fn test_cannot_send_edit_request ( ) -> Result < ( ) > {
3716
3716
let mut tcm = TestContextManager :: new ( ) ;
3717
3717
let alice = & tcm. alice ( ) . await ;
3718
3718
let bob = & tcm. bob ( ) . await ;
3719
- let chat = alice. create_chat ( bob) . await ;
3719
+ let chat_id = alice
3720
+ . create_group_with_members ( ProtectionStatus :: Unprotected , "My Group" , & [ bob] )
3721
+ . await ;
3722
+
3723
+ // Alice can edit her message
3724
+ let sent1 = alice. send_text ( chat_id, "foo" ) . await ;
3725
+ send_edit_request ( alice, sent1. sender_msg_id , "bar" . to_string ( ) ) . await ?;
3726
+
3727
+ // Bob cannot edit Alice's message
3728
+ let msg = bob. recv_msg ( & sent1) . await ;
3729
+ assert ! ( send_edit_request( bob, msg. id, "bar" . to_string( ) )
3730
+ . await
3731
+ . is_err( ) ) ;
3720
3732
3733
+ // HTML messages cannot be edited
3721
3734
let mut msg = Message :: new_text ( "plain text" . to_string ( ) ) ;
3722
3735
msg. set_html ( Some ( "<b>html</b> text" . to_string ( ) ) ) ;
3723
- send_msg ( alice , chat . id , & mut msg) . await . unwrap ( ) ;
3736
+ let sent2 = alice . send_msg ( chat_id , & mut msg) . await ;
3724
3737
assert ! ( msg. has_html( ) ) ;
3725
- assert ! ( send_edit_request( alice, msg. id, "foo" . to_string( ) )
3738
+ assert ! (
3739
+ send_edit_request( alice, sent2. sender_msg_id, "foo" . to_string( ) )
3740
+ . await
3741
+ . is_err( )
3742
+ ) ;
3743
+
3744
+ // Info messages cannot be edited
3745
+ set_chat_name ( alice, chat_id, "bar" ) . await ?;
3746
+ let msg = alice. get_last_msg ( ) . await ;
3747
+ assert ! ( msg. is_info( ) ) ;
3748
+ assert_eq ! ( msg. from_id, ContactId :: SELF ) ;
3749
+ assert ! ( send_edit_request( alice, msg. id, "bar" . to_string( ) )
3750
+ . await
3751
+ . is_err( ) ) ;
3752
+
3753
+ // Videochat invitations cannot be edited
3754
+ alice
3755
+ . set_config ( Config :: WebrtcInstance , Some ( "https://foo.bar" ) )
3756
+ . await ?;
3757
+ let msg_id = send_videochat_invitation ( alice, chat_id) . await ?;
3758
+ assert ! ( send_edit_request( alice, msg_id, "bar" . to_string( ) )
3726
3759
. await
3727
3760
. is_err( ) ) ;
3728
3761
3762
+ // If not text was given initally, there is nothing to edit
3763
+ // (this also avoids complexity in UI element changes; focus is typos and rewordings)
3764
+ let mut msg = Message :: new ( Viewtype :: File ) ;
3765
+ msg. make_vcard ( alice, & [ ContactId :: SELF ] ) . await ?;
3766
+ let sent3 = alice. send_msg ( chat_id, & mut msg) . await ;
3767
+ assert ! ( msg. text. is_empty( ) ) ;
3768
+ assert ! (
3769
+ send_edit_request( alice, sent3. sender_msg_id, "bar" . to_string( ) )
3770
+ . await
3771
+ . is_err( )
3772
+ ) ;
3773
+
3729
3774
Ok ( ( ) )
3730
3775
}
0 commit comments