introduce two new events

This commit is contained in:
Sebastian Klähn
2022-09-11 19:42:45 +02:00
parent 70979c55fa
commit 6877f16b63
8 changed files with 62 additions and 5 deletions

View File

@@ -307,4 +307,12 @@ pub enum EventType {
WebxdcInstanceDeleted {
msg_id: MsgId,
},
WebxdcBusyUpdating {
msg_id: MsgId,
},
WebxdcUpToDate {
msg_id: MsgId,
},
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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::{