Skip to content

Commit f2c02d1

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

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: src/chat.rs

+7
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,13 @@ 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 and not return webxdc `MsgId`s from the
799+
// transaction to not add LIMIT to SELECT above.
800+
for id in rows {
801+
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id: id? });
802+
}
796803
transaction.execute(
797804
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)",
798805
(delete_msgs_target, self,),

Diff for: src/webxdc/webxdc_tests.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,23 @@ 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+
let chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "foo").await?;
1796+
let instance = send_webxdc_instance(alice, chat_id).await?;
1797+
chat_id.delete(alice).await?;
1798+
let EventType::WebxdcInstanceDeleted { msg_id } = alice
1799+
.evtracker
1800+
.get_matching(|evt| matches!(evt, EventType::WebxdcInstanceDeleted { .. }))
1801+
.await
1802+
else {
1803+
unreachable!();
1804+
};
1805+
assert_eq!(msg_id, instance.id);
1806+
Ok(())
1807+
}
1808+
17921809
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
17931810
async fn change_logging_webxdc() -> Result<()> {
17941811
let alice = TestContext::new_alice().await;

0 commit comments

Comments
 (0)