api: add JSON-RPC API is_sending_finished()

This commit is contained in:
link2xt
2026-09-12 14:29:23 +00:00
committed by l
parent 0b2051cda4
commit 44387f5e58
5 changed files with 66 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ use crate::events::{Event, EventEmitter, EventType, Events};
use crate::location;
use crate::log::warn;
use crate::push::PushSubscriber;
use crate::smtp;
use crate::stock_str::StockStrings;
/// Account manager, that can handle multiple accounts in a single place.
@@ -509,6 +510,20 @@ impl Accounts {
)
}
/// Returns true if there are no pending messages for sending.
///
/// This is intended to be used by UIs to request not moving the app to background
/// when there are messages left in the queue.
pub async fn is_sending_finished(&self) -> Result<bool> {
let accounts: Vec<Context> = self.accounts.values().cloned().collect();
for account in accounts {
if !smtp::is_queue_empty(&account).await? {
return Ok(false);
}
}
Ok(true)
}
/// Interrupts ongoing background_fetch() call,
/// making it return early.
///

View File

@@ -751,3 +751,9 @@ pub(crate) async fn add_self_recipients(
Ok(())
}
/// Returns true if SMTP queue is empty.
pub(crate) async fn is_queue_empty(context: &Context) -> Result<bool> {
let sending_finished = !context.sql.exists("SELECT COUNT(*) FROM smtp", ()).await?;
Ok(sending_finished)
}