diff --git a/.gitignore b/.gitignore index 9bd11db3a..ab2f50a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ deltachat-ffi/xml coverage/ .DS_Store +.vscode/launch.json +python/accounts.txt +python/all-testaccounts.txt +tmp/ diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index a5d7b3341..fa53afc9c 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -21,7 +21,6 @@ use deltachat::message::{self, Message, MessageState, MsgId, Viewtype}; use deltachat::peerstate::*; use deltachat::qr::*; use deltachat::sql; -use deltachat::EventType; use deltachat::{config, provider}; use std::fs; use std::time::{Duration, SystemTime}; @@ -93,10 +92,7 @@ async fn reset_tables(context: &Context, bits: i32) { println!("(8) Rest but server config reset."); } - context.emit_event(EventType::MsgsChanged { - chat_id: ChatId::new(0), - msg_id: MsgId::new(0), - }); + context.emit_msgs_changed_without_ids(); } async fn poke_eml_file(context: &Context, filename: impl AsRef) -> Result<()> { @@ -164,10 +160,7 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool { } println!("Import: {} items read from \"{}\".", read_cnt, &real_spec); if read_cnt > 0 { - context.emit_event(EventType::MsgsChanged { - chat_id: ChatId::new(0), - msg_id: MsgId::new(0), - }); + context.emit_msgs_changed_without_ids(); } true } diff --git a/src/chat.rs b/src/chat.rs index c448a2111..fdf7c3665 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -214,10 +214,7 @@ impl ChatId { } } }; - context.emit_event(EventType::MsgsChanged { - chat_id: ChatId::new(0), - msg_id: MsgId::new(0), - }); + context.emit_msgs_changed_without_ids(); Ok(chat_id) } @@ -492,10 +489,7 @@ impl ChatId { }) .await?; - context.emit_event(EventType::MsgsChanged { - msg_id: MsgId::new(0), - chat_id: ChatId::new(0), - }); + context.emit_msgs_changed_without_ids(); Ok(()) } @@ -550,10 +544,7 @@ impl ChatId { .execute("DELETE FROM chats WHERE id=?;", paramsv![self]) .await?; - context.emit_event(EventType::MsgsChanged { - msg_id: MsgId::new(0), - chat_id: ChatId::new(0), - }); + context.emit_msgs_changed_without_ids(); context.set_config(Config::LastHousekeeping, None).await?; context.interrupt_inbox(InterruptInfo::new(false)).await; @@ -581,9 +572,9 @@ impl ChatId { }; if changed { - context.emit_event(EventType::MsgsChanged { - chat_id: self, - msg_id: if msg.is_some() { + context.emit_msgs_changed( + self, + if msg.is_some() { match self.get_draft_msg_id(context).await? { Some(msg_id) => msg_id, None => MsgId::new(0), @@ -591,7 +582,7 @@ impl ChatId { } else { MsgId::new(0) }, - }); + ); } Ok(()) @@ -1793,10 +1784,7 @@ pub async fn prepare_msg(context: &Context, chat_id: ChatId, msg: &mut Message) ); let msg_id = prepare_msg_common(context, chat_id, msg, MessageState::OutPreparing).await?; - context.emit_event(EventType::MsgsChanged { - chat_id: msg.chat_id, - msg_id: msg.id, - }); + context.emit_msgs_changed(msg.chat_id, msg.id); Ok(msg_id) } @@ -1964,20 +1952,14 @@ pub async fn send_msg_sync(context: &Context, chat_id: ChatId, msg: &mut Message .await .context("failed to send message, queued for later sending")?; - context.emit_event(EventType::MsgsChanged { - chat_id: msg.chat_id, - msg_id: msg.id, - }); + context.emit_msgs_changed(msg.chat_id, msg.id); } Ok(msg.id) } async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result { if prepare_send_msg(context, chat_id, msg).await?.is_some() { - context.emit_event(EventType::MsgsChanged { - chat_id: msg.chat_id, - msg_id: msg.id, - }); + context.emit_msgs_changed(msg.chat_id, msg.id); if msg.param.exists(Param::SetLatitude) { context.emit_event(EventType::LocationChanged(Some(ContactId::SELF))); @@ -2565,10 +2547,7 @@ pub async fn create_group_chat( add_to_chat_contacts_table(context, chat_id, ContactId::SELF).await?; } - context.emit_event(EventType::MsgsChanged { - msg_id: MsgId::new(0), - chat_id: ChatId::new(0), - }); + context.emit_msgs_changed_without_ids(); if protect == ProtectionStatus::Protected { // this part is to stay compatible to verified groups, @@ -2622,10 +2601,7 @@ pub async fn create_broadcast_list(context: &Context) -> Result { .await?; let chat_id = ChatId::new(u32::try_from(row_id)?); - context.emit_event(EventType::MsgsChanged { - msg_id: MsgId::new(0), - chat_id: ChatId::new(0), - }); + context.emit_msgs_changed_without_ids(); Ok(chat_id) } @@ -2988,10 +2964,7 @@ pub async fn set_chat_name(context: &Context, chat_id: ChatId, new_name: &str) - msg.param.set(Param::Arg, &chat.name); } msg.id = send_msg(context, chat_id, &mut msg).await?; - context.emit_event(EventType::MsgsChanged { - chat_id, - msg_id: msg.id, - }); + context.emit_msgs_changed(chat_id, msg.id); } context.emit_event(EventType::ChatModified(chat_id)); success = true; @@ -3053,10 +3026,7 @@ pub async fn set_chat_profile_image( chat.update_param(context).await?; if chat.is_promoted() && !chat.is_mailing_list() { msg.id = send_msg(context, chat_id, &mut msg).await?; - context.emit_event(EventType::MsgsChanged { - chat_id, - msg_id: msg.id, - }); + context.emit_msgs_changed(chat_id, msg.id); } context.emit_event(EventType::ChatModified(chat_id)); Ok(()) @@ -3151,10 +3121,7 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) } } for (chat_id, msg_id) in created_chats.iter().zip(created_msgs.iter()) { - context.emit_event(EventType::MsgsChanged { - chat_id: *chat_id, - msg_id: *msg_id, - }); + context.emit_msgs_changed(*chat_id, *msg_id); } Ok(()) } @@ -3294,9 +3261,9 @@ pub async fn add_device_msg_with_importance( if !msg_id.is_unset() { if important { - context.emit_event(EventType::IncomingMsg { chat_id, msg_id }); + context.emit_incoming_msg(chat_id, msg_id); } else { - context.emit_event(EventType::MsgsChanged { chat_id, msg_id }); + context.emit_msgs_changed(chat_id, msg_id); } } @@ -3391,7 +3358,8 @@ pub(crate) async fn add_info_msg_with_cmd( ).await?; let msg_id = MsgId::new(row_id.try_into()?); - context.emit_event(EventType::MsgsChanged { chat_id, msg_id }); + context.emit_msgs_changed(chat_id, msg_id); + Ok(msg_id) } diff --git a/src/context.rs b/src/context.rs index 56f35c817..fa54395fb 100644 --- a/src/context.rs +++ b/src/context.rs @@ -241,6 +241,24 @@ impl Context { }); } + /// Emits a generic MsgsChanged event (without chat or message id) + pub fn emit_msgs_changed_without_ids(&self) { + self.emit_event(EventType::MsgsChanged { + chat_id: ChatId::new(0), + msg_id: MsgId::new(0), + }); + } + + /// Emits a MsgsChanged event with specified chat and message ids + pub fn emit_msgs_changed(&self, chat_id: ChatId, msg_id: MsgId) { + self.emit_event(EventType::MsgsChanged { chat_id, msg_id }); + } + + /// Emits an IncomingMsg event with specified chat and message ids + pub fn emit_incoming_msg(&self, chat_id: ChatId, msg_id: MsgId) { + self.emit_event(EventType::IncomingMsg { chat_id, msg_id }); + } + /// Returns a receiver for emitted events. /// /// Multiple emitters can be created, but note that in this case each emitted event will diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index c6be9e942..e8f173a3c 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -329,18 +329,15 @@ pub(crate) async fn dc_receive_imf_inner( } if replace_partial_download { - context.emit_event(EventType::MsgsChanged { - msg_id: MsgId::new(0), - chat_id, - }); + context.emit_msgs_changed(chat_id, MsgId::new(0)); } else if !chat_id.is_trash() { + let fresh = added_parts.received_msg.state == MessageState::InFresh; for msg_id in added_parts.created_db_entries { - let event = if incoming && added_parts.received_msg.state == MessageState::InFresh { - EventType::IncomingMsg { msg_id, chat_id } + if incoming && fresh { + context.emit_incoming_msg(chat_id, msg_id); } else { - EventType::MsgsChanged { msg_id, chat_id } + context.emit_msgs_changed(chat_id, msg_id); }; - context.emit_event(event); } } diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 62249d64e..565dd8e00 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -399,10 +399,7 @@ WHERE } if updated { - context.emit_event(EventType::MsgsChanged { - chat_id: ChatId::new(0), - msg_id: MsgId::new(0), - }); + context.emit_msgs_changed_without_ids(); } Ok(()) diff --git a/src/message.rs b/src/message.rs index 10794cc3c..c2b4d6b8e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1254,10 +1254,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> { } if !msg_ids.is_empty() { - context.emit_event(EventType::MsgsChanged { - chat_id: ChatId::new(0), - msg_id: MsgId::new(0), - }); + context.emit_msgs_changed_without_ids(); // Run housekeeping to delete unused blobs. context.set_config(Config::LastHousekeeping, None).await?; diff --git a/src/webxdc.rs b/src/webxdc.rs index 023f5f7a2..99c9034b1 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -239,10 +239,7 @@ impl Context { { instance.param.set(Param::WebxdcSummary, summary); instance.update_param(self).await; - self.emit_event(EventType::MsgsChanged { - chat_id: instance.chat_id, - msg_id: instance.id, - }); + self.emit_msgs_changed(instance.chat_id, instance.id); } }