Skip to content

Commit df7b5c5

Browse files
committed
BackgroundFetchCompletedForAllAccounts event
1 parent 7690711 commit df7b5c5

File tree

8 files changed

+43
-5
lines changed

8 files changed

+43
-5
lines changed

deltachat-ffi/deltachat.h

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

62456245
#define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121
62466246

6247+
/**
6248+
* Tells that the Background fetch was completed (or timed out).
6249+
*
6250+
* This event acts as a marker, when you reach this event you can be sure
6251+
* that all events emitted during the background fetch were processed.
6252+
*
6253+
* This event is only emitted by the account manager
6254+
*/
6255+
6256+
#define DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS 2200
62476257

62486258
/**
62496259
* @}

deltachat-ffi/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
558558
EventType::SelfavatarChanged => 2110,
559559
EventType::WebxdcStatusUpdate { .. } => 2120,
560560
EventType::WebxdcInstanceDeleted { .. } => 2121,
561+
EventType::BackgroundFetchCompletedForAllAccounts => 2200,
561562
}
562563
}
563564

@@ -584,7 +585,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
584585
| EventType::ConnectivityChanged
585586
| EventType::SelfavatarChanged
586587
| EventType::IncomingMsgBunch { .. }
587-
| EventType::ErrorSelfNotInGroup(_) => 0,
588+
| EventType::ErrorSelfNotInGroup(_)
589+
| EventType::BackgroundFetchCompletedForAllAccounts => 0,
588590
EventType::MsgsChanged { chat_id, .. }
589591
| EventType::ReactionsChanged { chat_id, .. }
590592
| EventType::IncomingMsg { chat_id, .. }
@@ -643,7 +645,8 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
643645
| EventType::ConnectivityChanged
644646
| EventType::WebxdcInstanceDeleted { .. }
645647
| EventType::IncomingMsgBunch { .. }
646-
| EventType::SelfavatarChanged => 0,
648+
| EventType::SelfavatarChanged
649+
| EventType::BackgroundFetchCompletedForAllAccounts => 0,
647650
EventType::ChatModified(_) => 0,
648651
EventType::MsgsChanged { msg_id, .. }
649652
| EventType::ReactionsChanged { msg_id, .. }
@@ -705,6 +708,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
705708
| EventType::SelfavatarChanged
706709
| EventType::WebxdcStatusUpdate { .. }
707710
| EventType::WebxdcInstanceDeleted { .. }
711+
| EventType::BackgroundFetchCompletedForAllAccounts
708712
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
709713
EventType::ConfigureProgress { comment, .. } => {
710714
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
@@ -301,6 +301,13 @@ pub enum EventType {
301301
WebxdcInstanceDeleted {
302302
msg_id: u32,
303303
},
304+
305+
/// Tells that the Background fetch was completed (or timed out).
306+
/// This event acts as a marker, when you reach this event you can be sure
307+
/// that all events emitted during the background fetch were processed.
308+
///
309+
/// This event is only emitted by the account manager
310+
BackgroundFetchCompletedForAllAccounts,
304311
}
305312

306313
impl From<CoreEventType> for EventType {
@@ -406,6 +413,9 @@ impl From<CoreEventType> for EventType {
406413
CoreEventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
407414
msg_id: msg_id.to_u32(),
408415
},
416+
CoreEventType::BackgroundFetchCompletedForAllAccounts => {
417+
BackgroundFetchCompletedForAllAccounts
418+
}
409419
}
410420
}
411421
}

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
@@ -35,5 +35,6 @@ module.exports = {
3535
2100: 'DC_EVENT_CONNECTIVITY_CHANGED',
3636
2110: 'DC_EVENT_SELFAVATAR_CHANGED',
3737
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
38-
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED'
38+
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
39+
2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS'
3940
}

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,
@@ -321,4 +322,5 @@ export const EventId2EventName: { [key: number]: string } = {
321322
2110: 'DC_EVENT_SELFAVATAR_CHANGED',
322323
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
323324
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
325+
2200: 'DC_EVENT_BACKGROUND_FETCH_COMPLETED_FOR_ALL_ACCOUNTS',
324326
}

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
@@ -277,4 +277,11 @@ pub enum EventType {
277277
/// ID of the deleted message.
278278
msg_id: MsgId,
279279
},
280+
281+
/// Tells that the Background fetch was completed (or timed out).
282+
/// This event acts as a marker, when you reach this event you can be sure
283+
/// that all events emitted during the background fetch were processed.
284+
///
285+
/// This event is only emitted by the account manager
286+
BackgroundFetchCompletedForAllAccounts,
280287
}

0 commit comments

Comments
 (0)