Skip to content

Commit df455bb

Browse files
Simon-Lauxr10s
authored andcommitted
BackgroundFetchCompletedForAllAccounts event
1 parent 946eea4 commit df455bb

File tree

8 files changed

+42
-4
lines changed

8 files changed

+42
-4
lines changed

deltachat-ffi/deltachat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6269,6 +6269,16 @@ void dc_event_unref(dc_event_t* event);
62696269

62706270
#define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121
62716271

6272+
/**
6273+
* Tells that the Background fetch was completed (or timed out).
6274+
*
6275+
* This event acts as a marker, when you reach this event you can be sure
6276+
* that all events emitted during the background fetch were processed.
6277+
*
6278+
* This event is only emitted by the account manager
6279+
*/
6280+
6281+
#define DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS 2200
62726282

62736283
/**
62746284
* @}

deltachat-ffi/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
559559
EventType::ConfigSynced { .. } => 2111,
560560
EventType::WebxdcStatusUpdate { .. } => 2120,
561561
EventType::WebxdcInstanceDeleted { .. } => 2121,
562+
EventType::BackgroundFetchCompletedForAllAccounts => 2200,
562563
}
563564
}
564565

@@ -586,7 +587,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
586587
| EventType::SelfavatarChanged
587588
| EventType::ConfigSynced { .. }
588589
| EventType::IncomingMsgBunch { .. }
589-
| EventType::ErrorSelfNotInGroup(_) => 0,
590+
| EventType::ErrorSelfNotInGroup(_)
591+
| EventType::BackgroundFetchCompletedForAllAccounts => 0,
590592
EventType::MsgsChanged { chat_id, .. }
591593
| EventType::ReactionsChanged { chat_id, .. }
592594
| EventType::IncomingMsg { chat_id, .. }
@@ -646,6 +648,7 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
646648
| EventType::WebxdcInstanceDeleted { .. }
647649
| EventType::IncomingMsgBunch { .. }
648650
| EventType::SelfavatarChanged
651+
| EventType::BackgroundFetchCompletedForAllAccounts
649652
| EventType::ConfigSynced { .. } => 0,
650653
EventType::ChatModified(_) => 0,
651654
EventType::MsgsChanged { msg_id, .. }
@@ -708,6 +711,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
708711
| EventType::SelfavatarChanged
709712
| EventType::WebxdcStatusUpdate { .. }
710713
| EventType::WebxdcInstanceDeleted { .. }
714+
| EventType::BackgroundFetchCompletedForAllAccounts
711715
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
712716
EventType::ConfigureProgress { comment, .. } => {
713717
if let Some(comment) = comment {

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ pub enum EventType {
245245
/// Inform that a message containing a webxdc instance has been deleted
246246
#[serde(rename_all = "camelCase")]
247247
WebxdcInstanceDeleted { msg_id: u32 },
248+
249+
/// Tells that the Background fetch was completed (or timed out).
250+
/// This event acts as a marker, when you reach this event you can be sure
251+
/// that all events emitted during the background fetch were processed.
252+
///
253+
/// This event is only emitted by the account manager
254+
BackgroundFetchCompletedForAllAccounts,
248255
}
249256

250257
impl From<CoreEventType> for EventType {
@@ -353,6 +360,9 @@ impl From<CoreEventType> for EventType {
353360
CoreEventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
354361
msg_id: msg_id.to_u32(),
355362
},
363+
CoreEventType::BackgroundFetchCompletedForAllAccounts => {
364+
BackgroundFetchCompletedForAllAccounts
365+
}
356366
}
357367
}
358368
}

node/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
DC_DOWNLOAD_FAILURE: 20,
3030
DC_DOWNLOAD_IN_PROGRESS: 1000,
3131
DC_DOWNLOAD_UNDECIPHERABLE: 30,
32+
DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS: 2200,
3233
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED: 2021,
3334
DC_EVENT_CHAT_MODIFIED: 2020,
3435
DC_EVENT_CONFIGURE_PROGRESS: 2041,

node/events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ module.exports = {
3636
2110: 'DC_EVENT_SELFAVATAR_CHANGED',
3737
2111: 'DC_EVENT_CONFIG_SYNCED',
3838
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
39-
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED'
39+
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
40+
2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS'
4041
}

node/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum C {
2929
DC_DOWNLOAD_FAILURE = 20,
3030
DC_DOWNLOAD_IN_PROGRESS = 1000,
3131
DC_DOWNLOAD_UNDECIPHERABLE = 30,
32+
DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS = 2200,
3233
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED = 2021,
3334
DC_EVENT_CHAT_MODIFIED = 2020,
3435
DC_EVENT_CONFIGURE_PROGRESS = 2041,
@@ -326,4 +327,5 @@ export const EventId2EventName: { [key: number]: string } = {
326327
2111: 'DC_EVENT_CONFIG_SYNCED',
327328
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
328329
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
330+
2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS',
329331
}

src/accounts.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,17 @@ impl Accounts {
309309
.map(background_fetch_and_log_error),
310310
)
311311
.await;
312+
313+
self.emit_event(EventType::BackgroundFetchCompletedForAllAccounts);
312314
}
313315

314316
/// Performs a background fetch for all accounts in parallel with a timeout.
315317
///
316318
/// If you want no timeout, then use [Accounts::background_fetch] instead.
317319
pub async fn background_fetch_with_timeout(&self, timeout: std::time::Duration) -> Result<()> {
318-
tokio::time::timeout(timeout, self.background_fetch()).await?;
319-
Ok(())
320+
let result = tokio::time::timeout(timeout, self.background_fetch()).await;
321+
self.emit_event(EventType::BackgroundFetchCompletedForAllAccounts);
322+
result.map_err(|err| err.into())
320323
}
321324

322325
/// Emits a single event.

src/events/payload.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,11 @@ pub enum EventType {
287287
/// ID of the deleted message.
288288
msg_id: MsgId,
289289
},
290+
291+
/// Tells that the Background fetch was completed (or timed out).
292+
/// This event acts as a marker, when you reach this event you can be sure
293+
/// that all events emitted during the background fetch were processed.
294+
///
295+
/// This event is only emitted by the account manager
296+
BackgroundFetchCompletedForAllAccounts,
290297
}

0 commit comments

Comments
 (0)