Skip to content

Commit 5a5f2c5

Browse files
committed
fix: Emit WebxdcInstanceDeleted events when deleting a chat (#6670)
1 parent f72d27f commit 5a5f2c5

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/chat.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,14 @@ impl ChatId {
801801
Sync => chat.get_sync_id(context).await?,
802802
};
803803

804-
context
804+
let webxdc_ids = context
805805
.sql
806806
.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+
}
807812
transaction.execute(
808813
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)",
809814
(delete_msgs_target, self,),
@@ -819,10 +824,13 @@ impl ChatId {
819824
transaction.execute("DELETE FROM msgs WHERE chat_id=?", (self,))?;
820825
transaction.execute("DELETE FROM chats_contacts WHERE chat_id=?", (self,))?;
821826
transaction.execute("DELETE FROM chats WHERE id=?", (self,))?;
822-
Ok(())
827+
Ok(webxdc_ids)
823828
})
824829
.await?;
825830

831+
for msg_id in webxdc_ids {
832+
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id });
833+
}
826834
context.emit_event(EventType::ChatDeleted { chat_id: self });
827835
context.emit_msgs_changed_without_ids();
828836

src/webxdc/webxdc_tests.rs

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

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

0 commit comments

Comments
 (0)