Skip to content

Commit bb2fc3c

Browse files
committed
api: emit DC_EVENT_MSGS_CHANGED per chat when messages are deleted
1 parent 53d01db commit bb2fc3c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/ephemeral.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
//! ephemeral message timers or global `delete_server_after` setting.
6464
6565
use std::cmp::max;
66+
use std::collections::BTreeSet;
6667
use std::convert::{TryFrom, TryInto};
6768
use std::num::ParseIntError;
6869
use std::str::FromStr;
@@ -455,11 +456,16 @@ pub(crate) async fn delete_expired_messages(context: &Context, now: i64) -> Resu
455456
})
456457
.await?;
457458

459+
let mut modified_chat_ids = BTreeSet::new();
460+
458461
for (chat_id, msg_id) in msgs_changed {
459-
context.emit_event(EventType::MsgDeleted { chat_id, msg_id })
462+
context.emit_event(EventType::MsgDeleted { chat_id, msg_id });
463+
modified_chat_ids.insert(chat_id);
460464
}
461465

462-
context.emit_msgs_changed_without_ids();
466+
for modified_chat_id in modified_chat_ids {
467+
context.emit_msgs_changed(modified_chat_id, MsgId::new(0));
468+
}
463469

464470
for msg_id in webxdc_deleted {
465471
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id });

src/message.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,8 @@ pub async fn get_mime_headers(context: &Context, msg_id: MsgId) -> Result<Vec<u8
14211421
/// by moving them to the trash chat
14221422
/// and scheduling for deletion on IMAP.
14231423
pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
1424+
let mut modified_chat_ids = BTreeSet::new();
1425+
14241426
for &msg_id in msg_ids {
14251427
let msg = Message::load_from_db(context, msg_id).await?;
14261428
if msg.location_id > 0 {
@@ -1440,6 +1442,8 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
14401442
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id });
14411443
}
14421444

1445+
modified_chat_ids.insert(msg.chat_id);
1446+
14431447
let target = context.get_delete_msgs_target().await?;
14441448
context
14451449
.sql
@@ -1463,9 +1467,11 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
14631467
}
14641468
}
14651469

1466-
if !msg_ids.is_empty() {
1467-
context.emit_msgs_changed_without_ids();
1470+
for modified_chat_id in modified_chat_ids {
1471+
context.emit_msgs_changed(modified_chat_id, MsgId::new(0));
1472+
}
14681473

1474+
if !msg_ids.is_empty() {
14691475
// Run housekeeping to delete unused blobs.
14701476
context.set_config(Config::LastHousekeeping, None).await?;
14711477
}

0 commit comments

Comments
 (0)