api: emit DC_EVENT_MSGS_CHANGED per chat when messages are deleted

This commit is contained in:
link2xt
2023-06-06 15:55:47 +00:00
parent 33a014eea4
commit e6d9a49187
2 changed files with 16 additions and 4 deletions

View File

@@ -63,6 +63,7 @@
//! ephemeral message timers or global `delete_server_after` setting.
use std::cmp::max;
use std::collections::BTreeSet;
use std::convert::{TryFrom, TryInto};
use std::num::ParseIntError;
use std::str::FromStr;
@@ -455,11 +456,16 @@ pub(crate) async fn delete_expired_messages(context: &Context, now: i64) -> Resu
})
.await?;
let mut modified_chat_ids = BTreeSet::new();
for (chat_id, msg_id) in msgs_changed {
context.emit_event(EventType::MsgDeleted { chat_id, msg_id })
context.emit_event(EventType::MsgDeleted { chat_id, msg_id });
modified_chat_ids.insert(chat_id);
}
context.emit_msgs_changed_without_ids();
for modified_chat_id in modified_chat_ids {
context.emit_msgs_changed(modified_chat_id, MsgId::new(0));
}
for msg_id in webxdc_deleted {
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id });

View File

@@ -1421,6 +1421,8 @@ pub async fn get_mime_headers(context: &Context, msg_id: MsgId) -> Result<Vec<u8
/// by moving them to the trash chat
/// and scheduling for deletion on IMAP.
pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
let mut modified_chat_ids = BTreeSet::new();
for &msg_id in msg_ids {
let msg = Message::load_from_db(context, msg_id).await?;
if msg.location_id > 0 {
@@ -1440,6 +1442,8 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
context.emit_event(EventType::WebxdcInstanceDeleted { msg_id });
}
modified_chat_ids.insert(msg.chat_id);
let target = context.get_delete_msgs_target().await?;
context
.sql
@@ -1463,9 +1467,11 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
}
}
if !msg_ids.is_empty() {
context.emit_msgs_changed_without_ids();
for modified_chat_id in modified_chat_ids {
context.emit_msgs_changed(modified_chat_id, MsgId::new(0));
}
if !msg_ids.is_empty() {
// Run housekeeping to delete unused blobs.
context.set_config(Config::LastHousekeeping, None).await?;
}