mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
streamline emitting MsgsChanged and IncomingMsg event to go through particular functions.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -29,3 +29,7 @@ deltachat-ffi/xml
|
|||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode/launch.json
|
||||||
|
python/accounts.txt
|
||||||
|
python/all-testaccounts.txt
|
||||||
|
tmp/
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use deltachat::message::{self, Message, MessageState, MsgId, Viewtype};
|
|||||||
use deltachat::peerstate::*;
|
use deltachat::peerstate::*;
|
||||||
use deltachat::qr::*;
|
use deltachat::qr::*;
|
||||||
use deltachat::sql;
|
use deltachat::sql;
|
||||||
use deltachat::EventType;
|
|
||||||
use deltachat::{config, provider};
|
use deltachat::{config, provider};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
@@ -93,10 +92,7 @@ async fn reset_tables(context: &Context, bits: i32) {
|
|||||||
println!("(8) Rest but server config reset.");
|
println!("(8) Rest but server config reset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<()> {
|
async fn poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<()> {
|
||||||
@@ -164,10 +160,7 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool {
|
|||||||
}
|
}
|
||||||
println!("Import: {} items read from \"{}\".", read_cnt, &real_spec);
|
println!("Import: {} items read from \"{}\".", read_cnt, &real_spec);
|
||||||
if read_cnt > 0 {
|
if read_cnt > 0 {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
70
src/chat.rs
70
src/chat.rs
@@ -214,10 +214,7 @@ impl ChatId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
});
|
|
||||||
Ok(chat_id)
|
Ok(chat_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,10 +489,7 @@ impl ChatId {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -550,10 +544,7 @@ impl ChatId {
|
|||||||
.execute("DELETE FROM chats WHERE id=?;", paramsv![self])
|
.execute("DELETE FROM chats WHERE id=?;", paramsv![self])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
});
|
|
||||||
|
|
||||||
context.set_config(Config::LastHousekeeping, None).await?;
|
context.set_config(Config::LastHousekeeping, None).await?;
|
||||||
context.interrupt_inbox(InterruptInfo::new(false)).await;
|
context.interrupt_inbox(InterruptInfo::new(false)).await;
|
||||||
@@ -581,9 +572,9 @@ impl ChatId {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(
|
||||||
chat_id: self,
|
self,
|
||||||
msg_id: if msg.is_some() {
|
if msg.is_some() {
|
||||||
match self.get_draft_msg_id(context).await? {
|
match self.get_draft_msg_id(context).await? {
|
||||||
Some(msg_id) => msg_id,
|
Some(msg_id) => msg_id,
|
||||||
None => MsgId::new(0),
|
None => MsgId::new(0),
|
||||||
@@ -591,7 +582,7 @@ impl ChatId {
|
|||||||
} else {
|
} else {
|
||||||
MsgId::new(0)
|
MsgId::new(0)
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
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?;
|
let msg_id = prepare_msg_common(context, chat_id, msg, MessageState::OutPreparing).await?;
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(msg.chat_id, msg.id);
|
||||||
chat_id: msg.chat_id,
|
|
||||||
msg_id: msg.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
@@ -1964,20 +1952,14 @@ pub async fn send_msg_sync(context: &Context, chat_id: ChatId, msg: &mut Message
|
|||||||
.await
|
.await
|
||||||
.context("failed to send message, queued for later sending")?;
|
.context("failed to send message, queued for later sending")?;
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(msg.chat_id, msg.id);
|
||||||
chat_id: msg.chat_id,
|
|
||||||
msg_id: msg.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Ok(msg.id)
|
Ok(msg.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
|
async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
|
||||||
if prepare_send_msg(context, chat_id, msg).await?.is_some() {
|
if prepare_send_msg(context, chat_id, msg).await?.is_some() {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(msg.chat_id, msg.id);
|
||||||
chat_id: msg.chat_id,
|
|
||||||
msg_id: msg.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if msg.param.exists(Param::SetLatitude) {
|
if msg.param.exists(Param::SetLatitude) {
|
||||||
context.emit_event(EventType::LocationChanged(Some(ContactId::SELF)));
|
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?;
|
add_to_chat_contacts_table(context, chat_id, ContactId::SELF).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
});
|
|
||||||
|
|
||||||
if protect == ProtectionStatus::Protected {
|
if protect == ProtectionStatus::Protected {
|
||||||
// this part is to stay compatible to verified groups,
|
// this part is to stay compatible to verified groups,
|
||||||
@@ -2622,10 +2601,7 @@ pub async fn create_broadcast_list(context: &Context) -> Result<ChatId> {
|
|||||||
.await?;
|
.await?;
|
||||||
let chat_id = ChatId::new(u32::try_from(row_id)?);
|
let chat_id = ChatId::new(u32::try_from(row_id)?);
|
||||||
|
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
});
|
|
||||||
Ok(chat_id)
|
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.param.set(Param::Arg, &chat.name);
|
||||||
}
|
}
|
||||||
msg.id = send_msg(context, chat_id, &mut msg).await?;
|
msg.id = send_msg(context, chat_id, &mut msg).await?;
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(chat_id, msg.id);
|
||||||
chat_id,
|
|
||||||
msg_id: msg.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
context.emit_event(EventType::ChatModified(chat_id));
|
context.emit_event(EventType::ChatModified(chat_id));
|
||||||
success = true;
|
success = true;
|
||||||
@@ -3053,10 +3026,7 @@ pub async fn set_chat_profile_image(
|
|||||||
chat.update_param(context).await?;
|
chat.update_param(context).await?;
|
||||||
if chat.is_promoted() && !chat.is_mailing_list() {
|
if chat.is_promoted() && !chat.is_mailing_list() {
|
||||||
msg.id = send_msg(context, chat_id, &mut msg).await?;
|
msg.id = send_msg(context, chat_id, &mut msg).await?;
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(chat_id, msg.id);
|
||||||
chat_id,
|
|
||||||
msg_id: msg.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
context.emit_event(EventType::ChatModified(chat_id));
|
context.emit_event(EventType::ChatModified(chat_id));
|
||||||
Ok(())
|
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()) {
|
for (chat_id, msg_id) in created_chats.iter().zip(created_msgs.iter()) {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(*chat_id, *msg_id);
|
||||||
chat_id: *chat_id,
|
|
||||||
msg_id: *msg_id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -3294,9 +3261,9 @@ pub async fn add_device_msg_with_importance(
|
|||||||
|
|
||||||
if !msg_id.is_unset() {
|
if !msg_id.is_unset() {
|
||||||
if important {
|
if important {
|
||||||
context.emit_event(EventType::IncomingMsg { chat_id, msg_id });
|
context.emit_incoming_msg(chat_id, msg_id);
|
||||||
} else {
|
} 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?;
|
).await?;
|
||||||
|
|
||||||
let msg_id = MsgId::new(row_id.try_into()?);
|
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)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
/// Returns a receiver for emitted events.
|
||||||
///
|
///
|
||||||
/// Multiple emitters can be created, but note that in this case each emitted event will
|
/// Multiple emitters can be created, but note that in this case each emitted event will
|
||||||
|
|||||||
@@ -329,18 +329,15 @@ pub(crate) async fn dc_receive_imf_inner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if replace_partial_download {
|
if replace_partial_download {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed(chat_id, MsgId::new(0));
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
chat_id,
|
|
||||||
});
|
|
||||||
} else if !chat_id.is_trash() {
|
} else if !chat_id.is_trash() {
|
||||||
|
let fresh = added_parts.received_msg.state == MessageState::InFresh;
|
||||||
for msg_id in added_parts.created_db_entries {
|
for msg_id in added_parts.created_db_entries {
|
||||||
let event = if incoming && added_parts.received_msg.state == MessageState::InFresh {
|
if incoming && fresh {
|
||||||
EventType::IncomingMsg { msg_id, chat_id }
|
context.emit_incoming_msg(chat_id, msg_id);
|
||||||
} else {
|
} else {
|
||||||
EventType::MsgsChanged { msg_id, chat_id }
|
context.emit_msgs_changed(chat_id, msg_id);
|
||||||
};
|
};
|
||||||
context.emit_event(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -399,10 +399,7 @@ WHERE
|
|||||||
}
|
}
|
||||||
|
|
||||||
if updated {
|
if updated {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1254,10 +1254,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !msg_ids.is_empty() {
|
if !msg_ids.is_empty() {
|
||||||
context.emit_event(EventType::MsgsChanged {
|
context.emit_msgs_changed_without_ids();
|
||||||
chat_id: ChatId::new(0),
|
|
||||||
msg_id: MsgId::new(0),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Run housekeeping to delete unused blobs.
|
// Run housekeeping to delete unused blobs.
|
||||||
context.set_config(Config::LastHousekeeping, None).await?;
|
context.set_config(Config::LastHousekeeping, None).await?;
|
||||||
|
|||||||
@@ -239,10 +239,7 @@ impl Context {
|
|||||||
{
|
{
|
||||||
instance.param.set(Param::WebxdcSummary, summary);
|
instance.param.set(Param::WebxdcSummary, summary);
|
||||||
instance.update_param(self).await;
|
instance.update_param(self).await;
|
||||||
self.emit_event(EventType::MsgsChanged {
|
self.emit_msgs_changed(instance.chat_id, instance.id);
|
||||||
chat_id: instance.chat_id,
|
|
||||||
msg_id: instance.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user