Skip to content

Commit 90a840b

Browse files
committed
fix: Emit WebxdcInstanceDeleted events when deleting a chat (#6670)
1 parent f472c05 commit 90a840b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/chat.rs

+8
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,14 @@ impl ChatId {
793793
context
794794
.sql
795795
.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+
}
796804
transaction.execute(
797805
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)",
798806
(delete_msgs_target, self,),

src/webxdc/webxdc_tests.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,37 @@ async fn test_webxdc_delete_event() -> Result<()> {
17891789
Ok(())
17901790
}
17911791

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+
17921823
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
17931824
async fn change_logging_webxdc() -> Result<()> {
17941825
let alice = TestContext::new_alice().await;

0 commit comments

Comments
 (0)