File tree 2 files changed +41
-2
lines changed
2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -801,9 +801,14 @@ impl ChatId {
801
801
Sync => chat. get_sync_id ( context) . await ?,
802
802
} ;
803
803
804
- context
804
+ let webxdc_ids = context
805
805
. sql
806
806
. transaction ( |transaction| {
807
+ let mut stmt = transaction. prepare ( "SELECT id FROM msgs WHERE chat_id=? AND type=?" ) ?;
808
+ let mut webxdc_ids = Vec :: new ( ) ;
809
+ for id in stmt. query_map ( ( self , Viewtype :: Webxdc ) , |row| row. get ( 0 ) ) ? {
810
+ webxdc_ids. push ( id?) ;
811
+ }
807
812
transaction. execute (
808
813
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)" ,
809
814
( delete_msgs_target, self , ) ,
@@ -819,10 +824,13 @@ impl ChatId {
819
824
transaction. execute ( "DELETE FROM msgs WHERE chat_id=?" , ( self , ) ) ?;
820
825
transaction. execute ( "DELETE FROM chats_contacts WHERE chat_id=?" , ( self , ) ) ?;
821
826
transaction. execute ( "DELETE FROM chats WHERE id=?" , ( self , ) ) ?;
822
- Ok ( ( ) )
827
+ Ok ( webxdc_ids )
823
828
} )
824
829
. await ?;
825
830
831
+ for msg_id in webxdc_ids {
832
+ context. emit_event ( EventType :: WebxdcInstanceDeleted { msg_id } ) ;
833
+ }
826
834
context. emit_event ( EventType :: ChatDeleted { chat_id : self } ) ;
827
835
context. emit_msgs_changed_without_ids ( ) ;
828
836
Original file line number Diff line number Diff line change @@ -1790,6 +1790,37 @@ async fn test_webxdc_delete_event() -> Result<()> {
1790
1790
Ok ( ( ) )
1791
1791
}
1792
1792
1793
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1794
+ async fn test_chat_delete ( ) -> Result < ( ) > {
1795
+ let alice = & TestContext :: new_alice ( ) . await ;
1796
+
1797
+ let chat_id = create_group_chat ( alice, ProtectionStatus :: Unprotected , "foo" ) . await ?;
1798
+ send_webxdc_instance ( alice, chat_id) . await ?;
1799
+
1800
+ let chat_id = create_group_chat ( alice, ProtectionStatus :: Unprotected , "bar" ) . await ?;
1801
+ let instance = send_webxdc_instance ( alice, chat_id) . await ?;
1802
+ alice. send_text ( chat_id, "wtf" ) . await ;
1803
+
1804
+ chat_id. delete ( alice) . await ?;
1805
+ let EventType :: WebxdcInstanceDeleted { msg_id } = alice
1806
+ . evtracker
1807
+ . get_matching ( |evt| matches ! ( evt, EventType :: WebxdcInstanceDeleted { .. } ) )
1808
+ . await
1809
+ else {
1810
+ unreachable ! ( ) ;
1811
+ } ;
1812
+ assert_eq ! ( msg_id, instance. id) ;
1813
+ assert ! ( alice
1814
+ . evtracker
1815
+ . get_matching_opt( alice, |evt| matches!(
1816
+ evt,
1817
+ EventType :: WebxdcInstanceDeleted { .. }
1818
+ ) )
1819
+ . await
1820
+ . is_none( ) ) ;
1821
+ Ok ( ( ) )
1822
+ }
1823
+
1793
1824
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1794
1825
async fn change_logging_webxdc ( ) -> Result < ( ) > {
1795
1826
let alice = TestContext :: new_alice ( ) . await ;
You can’t perform that action at this time.
0 commit comments