mirror of
https://github.com/chatmail/core.git
synced 2026-09-22 13:01:21 +03:00
api: add JSON-RPC API is_sending_finished()
This commit is contained in:
@@ -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.
|
||||
///
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user