File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -793,6 +793,14 @@ impl ChatId {
793
793
context
794
794
. sql
795
795
. transaction ( |transaction| {
796
+ let mut stmt = transaction. prepare ( "SELECT id FROM msgs WHERE chat_id=? AND type=?" ) ?;
797
+ let rows = stmt. query_map ( ( self , Viewtype :: Webxdc ) , |row| row. get ( 0 ) ) ?;
798
+ // Let's emit events optimistically (before the transaction completes) and not
799
+ // return webxdc `MsgId`s from the transaction because otherwise we need a vector of
800
+ // indefinite size in memory.
801
+ for id in rows {
802
+ context. emit_event ( EventType :: WebxdcInstanceDeleted { msg_id : id? } ) ;
803
+ }
796
804
transaction. execute (
797
805
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)" ,
798
806
( delete_msgs_target, self , ) ,
Original file line number Diff line number Diff line change @@ -1789,6 +1789,37 @@ async fn test_webxdc_delete_event() -> Result<()> {
1789
1789
Ok ( ( ) )
1790
1790
}
1791
1791
1792
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1793
+ async fn test_chat_delete ( ) -> Result < ( ) > {
1794
+ let alice = & TestContext :: new_alice ( ) . await ;
1795
+
1796
+ let chat_id = create_group_chat ( alice, ProtectionStatus :: Unprotected , "foo" ) . await ?;
1797
+ send_webxdc_instance ( alice, chat_id) . await ?;
1798
+
1799
+ let chat_id = create_group_chat ( alice, ProtectionStatus :: Unprotected , "bar" ) . await ?;
1800
+ let instance = send_webxdc_instance ( alice, chat_id) . await ?;
1801
+ alice. send_text ( chat_id, "wtf" ) . await ;
1802
+
1803
+ chat_id. delete ( alice) . await ?;
1804
+ let EventType :: WebxdcInstanceDeleted { msg_id } = alice
1805
+ . evtracker
1806
+ . get_matching ( |evt| matches ! ( evt, EventType :: WebxdcInstanceDeleted { .. } ) )
1807
+ . await
1808
+ else {
1809
+ unreachable ! ( ) ;
1810
+ } ;
1811
+ assert_eq ! ( msg_id, instance. id) ;
1812
+ assert ! ( alice
1813
+ . evtracker
1814
+ . get_matching_opt( alice, |evt| matches!(
1815
+ evt,
1816
+ EventType :: WebxdcInstanceDeleted { .. }
1817
+ ) )
1818
+ . await
1819
+ . is_none( ) ) ;
1820
+ Ok ( ( ) )
1821
+ }
1822
+
1792
1823
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1793
1824
async fn change_logging_webxdc ( ) -> Result < ( ) > {
1794
1825
let alice = TestContext :: new_alice ( ) . await ;
You can’t perform that action at this time.
0 commit comments