From e53c88ecb8891d232546df778fc1e04d0798aff6 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 21 Jul 2020 00:33:49 +0200 Subject: [PATCH 1/3] add a macro that sends out DC_EVENT_ERROR_NETWORK and takes an Error as parameter. DC_EVENT_ERROR_NETWORK errors may be handled differently in the uis --- src/log.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/log.rs b/src/log.rs index 38e3c2f9e..9b253b93d 100644 --- a/src/log.rs +++ b/src/log.rs @@ -41,6 +41,17 @@ macro_rules! error { }}; } +#[macro_export] +macro_rules! error_network { + ($ctx:expr, $msg:expr) => { + error_network!($ctx, $msg,) + }; + ($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{ + let formatted = format!($msg, $($args),*); + emit_event!($ctx, $crate::Event::ErrorNetwork(formatted)); + }}; +} + #[macro_export] macro_rules! emit_event { ($ctx:expr, $event:expr) => { From 94035d6286af5280847fae2289efc49c15857de1 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 21 Jul 2020 00:36:21 +0200 Subject: [PATCH 2/3] show errors from connect_configured() (as 'IMAP Connect without configured params' (ConnectWithoutConfigure)) as DC_EVENT_ERROR_NETWORK as these may not be shown to the user if there is actually no internet --- src/scheduler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scheduler.rs b/src/scheduler.rs index 269f6f4e0..9688bbba1 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -105,7 +105,7 @@ async fn fetch(ctx: &Context, connection: &mut Imap) { match ctx.get_config(Config::ConfiguredInboxFolder).await { Some(watch_folder) => { if let Err(err) = connection.connect_configured(&ctx).await { - error!(ctx, "{}", err); + error_network!(ctx, "{}", err); return; } From dcf6a412393f008e03e02f97791b303af4dd0415 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 21 Jul 2020 00:57:08 +0200 Subject: [PATCH 3/3] update docs --- deltachat-ffi/deltachat.h | 4 +--- src/events.rs | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index c996eb3ce..4b0e526df 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4132,14 +4132,12 @@ void dc_event_unref(dc_event_t* event); * Network errors should be reported to users in a non-disturbing way, * however, as network errors may come in a sequence, * it is not useful to raise each an every error to the user. - * For this purpose, data1 is set to 1 if the error is probably worth reporting. * * Moreover, if the UI detects that the device is offline, * it is probably more useful to report this to the user * instead of the string from data2. * - * @param data1 (int) 1=first/new network error, should be reported the user; - * 0=subsequent network error, should be logged only + * @param data1 0 * @param data2 (char*) Error string, always set, never NULL. */ #define DC_EVENT_ERROR_NETWORK 401 diff --git a/src/events.rs b/src/events.rs index c58b9183d..d3353862c 100644 --- a/src/events.rs +++ b/src/events.rs @@ -140,7 +140,6 @@ pub enum Event { /// Network errors should be reported to users in a non-disturbing way, /// however, as network errors may come in a sequence, /// it is not useful to raise each an every error to the user. - /// For this purpose, data1 is set to 1 if the error is probably worth reporting. /// /// Moreover, if the UI detects that the device is offline, /// it is probably more useful to report this to the user