diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 6f94fc5fd..48d9a60de 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -6269,6 +6269,16 @@ void dc_event_unref(dc_event_t* event); #define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121 +/** + * Tells that the Background fetch was completed (or timed out). + * + * This event acts as a marker, when you reach this event you can be sure + * that all events emitted during the background fetch were processed. + * + * This event is only emitted by the account manager + */ + +#define DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS 2200 /** * @} diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 2ffe634ae..c52404cc4 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -559,6 +559,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int EventType::ConfigSynced { .. } => 2111, EventType::WebxdcStatusUpdate { .. } => 2120, EventType::WebxdcInstanceDeleted { .. } => 2121, + EventType::BackgroundFetchCompletedForAllAccounts => 2200, } } @@ -586,7 +587,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc: | EventType::SelfavatarChanged | EventType::ConfigSynced { .. } | EventType::IncomingMsgBunch { .. } - | EventType::ErrorSelfNotInGroup(_) => 0, + | EventType::ErrorSelfNotInGroup(_) + | EventType::BackgroundFetchCompletedForAllAccounts => 0, EventType::MsgsChanged { chat_id, .. } | EventType::ReactionsChanged { chat_id, .. } | EventType::IncomingMsg { chat_id, .. } @@ -646,6 +648,7 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc: | EventType::WebxdcInstanceDeleted { .. } | EventType::IncomingMsgBunch { .. } | EventType::SelfavatarChanged + | EventType::BackgroundFetchCompletedForAllAccounts | EventType::ConfigSynced { .. } => 0, EventType::ChatModified(_) => 0, EventType::MsgsChanged { msg_id, .. } @@ -708,6 +711,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut | EventType::SelfavatarChanged | EventType::WebxdcStatusUpdate { .. } | EventType::WebxdcInstanceDeleted { .. } + | EventType::BackgroundFetchCompletedForAllAccounts | EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(), EventType::ConfigureProgress { comment, .. } => { if let Some(comment) = comment { diff --git a/deltachat-jsonrpc/src/api/types/events.rs b/deltachat-jsonrpc/src/api/types/events.rs index c1feee63c..a92ef2e03 100644 --- a/deltachat-jsonrpc/src/api/types/events.rs +++ b/deltachat-jsonrpc/src/api/types/events.rs @@ -245,6 +245,13 @@ pub enum EventType { /// Inform that a message containing a webxdc instance has been deleted #[serde(rename_all = "camelCase")] WebxdcInstanceDeleted { msg_id: u32 }, + + /// Tells that the Background fetch was completed (or timed out). + /// This event acts as a marker, when you reach this event you can be sure + /// that all events emitted during the background fetch were processed. + /// + /// This event is only emitted by the account manager + BackgroundFetchCompletedForAllAccounts, } impl From for EventType { @@ -353,6 +360,9 @@ impl From for EventType { CoreEventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted { msg_id: msg_id.to_u32(), }, + CoreEventType::BackgroundFetchCompletedForAllAccounts => { + BackgroundFetchCompletedForAllAccounts + } } } } diff --git a/node/constants.js b/node/constants.js index 7c50ca55d..d980baf2d 100644 --- a/node/constants.js +++ b/node/constants.js @@ -29,6 +29,7 @@ module.exports = { DC_DOWNLOAD_FAILURE: 20, DC_DOWNLOAD_IN_PROGRESS: 1000, DC_DOWNLOAD_UNDECIPHERABLE: 30, + DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS: 2200, DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED: 2021, DC_EVENT_CHAT_MODIFIED: 2020, DC_EVENT_CONFIGURE_PROGRESS: 2041, diff --git a/node/events.js b/node/events.js index a618d4599..b418bf6ab 100644 --- a/node/events.js +++ b/node/events.js @@ -36,5 +36,6 @@ module.exports = { 2110: 'DC_EVENT_SELFAVATAR_CHANGED', 2111: 'DC_EVENT_CONFIG_SYNCED', 2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE', - 2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED' + 2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED', + 2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS' } diff --git a/node/lib/constants.ts b/node/lib/constants.ts index 9eba1b4b6..5c4c3b42d 100644 --- a/node/lib/constants.ts +++ b/node/lib/constants.ts @@ -29,6 +29,7 @@ export enum C { DC_DOWNLOAD_FAILURE = 20, DC_DOWNLOAD_IN_PROGRESS = 1000, DC_DOWNLOAD_UNDECIPHERABLE = 30, + DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS = 2200, DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED = 2021, DC_EVENT_CHAT_MODIFIED = 2020, DC_EVENT_CONFIGURE_PROGRESS = 2041, @@ -326,4 +327,5 @@ export const EventId2EventName: { [key: number]: string } = { 2111: 'DC_EVENT_CONFIG_SYNCED', 2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE', 2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED', + 2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS', } diff --git a/src/accounts.rs b/src/accounts.rs index de4daab57..c3977bbeb 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -309,14 +309,17 @@ impl Accounts { .map(background_fetch_and_log_error), ) .await; + + self.emit_event(EventType::BackgroundFetchCompletedForAllAccounts); } /// Performs a background fetch for all accounts in parallel with a timeout. /// /// If you want no timeout, then use [Accounts::background_fetch] instead. pub async fn background_fetch_with_timeout(&self, timeout: std::time::Duration) -> Result<()> { - tokio::time::timeout(timeout, self.background_fetch()).await?; - Ok(()) + let result = tokio::time::timeout(timeout, self.background_fetch()).await; + self.emit_event(EventType::BackgroundFetchCompletedForAllAccounts); + result.map_err(|err| err.into()) } /// Emits a single event. diff --git a/src/events/payload.rs b/src/events/payload.rs index d2cf3f476..43c167362 100644 --- a/src/events/payload.rs +++ b/src/events/payload.rs @@ -287,4 +287,11 @@ pub enum EventType { /// ID of the deleted message. msg_id: MsgId, }, + + /// Tells that the Background fetch was completed (or timed out). + /// This event acts as a marker, when you reach this event you can be sure + /// that all events emitted during the background fetch were processed. + /// + /// This event is only emitted by the account manager + BackgroundFetchCompletedForAllAccounts, }