mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 22:06:29 +03:00
introduce two new events
This commit is contained in:
@@ -307,4 +307,12 @@ pub enum EventType {
|
||||
WebxdcInstanceDeleted {
|
||||
msg_id: MsgId,
|
||||
},
|
||||
|
||||
WebxdcBusyUpdating {
|
||||
msg_id: MsgId,
|
||||
},
|
||||
|
||||
WebxdcUpToDate {
|
||||
msg_id: MsgId,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect
|
||||
if !duration_until_can_send.is_zero() {
|
||||
info!(
|
||||
ctx,
|
||||
"smtp got rate limited, waiting for {} until can send again",
|
||||
"smtp got rate limited, delaying next try by {}",
|
||||
duration_to_str(duration_until_can_send)
|
||||
);
|
||||
tokio::time::timeout(duration_until_can_send, async {
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::mimefactory::MimeFactory;
|
||||
use crate::oauth2::get_oauth2_access_token;
|
||||
use crate::provider::Socket;
|
||||
use crate::sql;
|
||||
use crate::webxdc::get_busy_webxdc_instances;
|
||||
use crate::{context::Context, scheduler::connectivity::ConnectivityStore};
|
||||
|
||||
/// SMTP write and read timeout in seconds.
|
||||
@@ -499,7 +500,15 @@ async fn send_mdns(context: &Context, connection: &mut Smtp) -> Result<()> {
|
||||
pub(crate) async fn send_smtp_messages(context: &Context, connection: &mut Smtp) -> Result<()> {
|
||||
let ratelimited = if context.ratelimit.read().await.can_send() {
|
||||
// add status updates and sync messages to end of sending queue
|
||||
|
||||
let update_needed = get_busy_webxdc_instances();
|
||||
context.flush_status_updates().await?;
|
||||
let update_needed_after_sending = get_busy_webxdc_instances();
|
||||
|
||||
for msg_id in update_needed.difference(&update_needed_after_sending) {
|
||||
context.emit_event(EventType::WebxdcUpToDate { msg_id: *msg_id })
|
||||
}
|
||||
|
||||
context.send_sync_msg().await?;
|
||||
false
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! # Handle webxdc messages.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::convert::TryFrom;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -377,6 +378,10 @@ impl Context {
|
||||
)
|
||||
.await?;
|
||||
|
||||
self.emit_event(EventType::WebxdcBusyUpdating {
|
||||
msg_id: instance.id,
|
||||
});
|
||||
|
||||
if send_now {
|
||||
self.sql.insert(
|
||||
"INSERT INTO smtp_status_updates (msg_id, first_serial, last_serial, descr) VALUES(?, ?, ?, ?)
|
||||
@@ -390,7 +395,6 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Pops one record of queued webxdc status updates.
|
||||
/// This function exists to make the sqlite statement testable.
|
||||
async fn pop_smtp_status_update(
|
||||
&self,
|
||||
) -> Result<Option<(MsgId, StatusUpdateSerial, StatusUpdateSerial, String)>> {
|
||||
@@ -744,6 +748,12 @@ impl Message {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a hashset of all webxdc instaces which still have updates to send
|
||||
pub(crate) fn get_busy_webxdc_instances() -> HashSet<MsgId> {
|
||||
// TODO: add sql statement to find that out
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::chat::{
|
||||
|
||||
Reference in New Issue
Block a user