diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 8025620ef..d9aba5b96 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2567,7 +2567,12 @@ pub unsafe extern "C" fn dc_set_location( } let ctx = &*context; - block_on(location::set(ctx, latitude, longitude, accuracy)) as _ + block_on(async move { + location::set(ctx, latitude, longitude, accuracy) + .await + .log_err(ctx) + .unwrap_or_default() + }) as libc::c_int } #[no_mangle] diff --git a/deltachat-repl/src/cmdline.rs b/deltachat-repl/src/cmdline.rs index 240998a95..e0168a28f 100644 --- a/deltachat-repl/src/cmdline.rs +++ b/deltachat-repl/src/cmdline.rs @@ -894,7 +894,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu let latitude = arg1.parse()?; let longitude = arg2.parse()?; - let continue_streaming = location::set(&context, latitude, longitude, 0.).await; + let continue_streaming = location::set(&context, latitude, longitude, 0.).await?; if continue_streaming { println!("Success, streaming should be continued."); } else { diff --git a/src/location.rs b/src/location.rs index 099ea3da9..ab3549516 100644 --- a/src/location.rs +++ b/src/location.rs @@ -328,13 +328,13 @@ pub async fn is_sending_locations_to_chat( } /// Sets current location of the user device. -pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64) -> bool { +pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64) -> Result { if latitude == 0.0 && longitude == 0.0 { - return true; + return Ok(true); } let mut continue_streaming = false; - if let Ok(chats) = context + let chats = context .sql .query_map( "SELECT id FROM chats WHERE locations_send_until>?;", @@ -346,33 +346,29 @@ pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64 .map_err(Into::into) }, ) - .await - { - for chat_id in chats { - if let Err(err) = context.sql.execute( - "INSERT INTO locations \ - (latitude, longitude, accuracy, timestamp, chat_id, from_id) VALUES (?,?,?,?,?,?);", - ( - latitude, - longitude, - accuracy, - time(), - chat_id, - ContactId::SELF, - ) - ).await { - warn!(context, "failed to store location {:#}", err); - } else { - info!(context, "stored location for chat {}", chat_id); - continue_streaming = true; - } - } - if continue_streaming { - context.emit_event(EventType::LocationChanged(Some(ContactId::SELF))); - }; - } + .await?; - continue_streaming + for chat_id in chats { + context.sql.execute( + "INSERT INTO locations \ + (latitude, longitude, accuracy, timestamp, chat_id, from_id) VALUES (?,?,?,?,?,?);", + ( + latitude, + longitude, + accuracy, + time(), + chat_id, + ContactId::SELF, + )).await.context("Failed to store location")?; + + info!(context, "Stored location for chat {chat_id}."); + continue_streaming = true; + } + if continue_streaming { + context.emit_event(EventType::LocationChanged(Some(ContactId::SELF))); + }; + + Ok(continue_streaming) } /// Searches for locations in the given time range, optionally filtering by chat and contact IDs.