diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index cdcc72274..7f708cd62 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4390,9 +4390,9 @@ int dc_msg_has_deviating_timestamp(const dc_msg_t* msg); /** - * Check if a message has a location bound to it. - * These messages are also returned by dc_get_locations() - * and the UI may decide to display a special icon beside such messages, + * Check if a message has a POI location bound to it. + * These locations are also returned by dc_get_locations() + * The UI may decide to display a special icon beside such messages. * * @memberof dc_msg_t * @param msg The message object. diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index 33a4b9ab5..a7e7a360d 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -35,6 +35,10 @@ pub struct MessageObject { parent_id: Option, text: String, + + /// Check if a message has a POI location bound to it. + /// These locations are also returned by `get_locations` method. + /// The UI may decide to display a special icon beside such messages. has_location: bool, has_html: bool, view_type: MessageViewtype, diff --git a/src/chat.rs b/src/chat.rs index f7ef21be6..3020a1b95 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2835,17 +2835,10 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) - .await?; } - if let Some(last_added_location_id) = rendered_msg.last_added_location_id { + if rendered_msg.last_added_location_id.is_some() { if let Err(err) = location::set_kml_sent_timestamp(context, msg.chat_id, now).await { error!(context, "Failed to set kml sent_timestamp: {err:#}."); } - if !msg.hidden { - if let Err(err) = - location::set_msg_location_id(context, msg.id, last_added_location_id).await - { - error!(context, "Failed to set msg_location_id: {err:#}."); - } - } } if let Some(sync_ids) = rendered_msg.sync_ids_to_delete { diff --git a/src/location.rs b/src/location.rs index 6a9ea2fa3..452f2c5cc 100644 --- a/src/location.rs +++ b/src/location.rs @@ -1037,6 +1037,8 @@ Content-Disposition: attachment; filename="location.kml" let mut msg = Message::new(Viewtype::Image); msg.set_file(file.to_str().unwrap(), None); let sent = alice.send_msg(alice_chat.id, &mut msg).await; + let alice_msg = Message::load_from_db(&alice, sent.sender_msg_id).await?; + assert_eq!(alice_msg.has_location(), false); let msg = bob.recv_msg_opt(&sent).await.unwrap(); assert!(msg.chat_id == bob_chat_id); @@ -1045,6 +1047,10 @@ Content-Disposition: attachment; filename="location.kml" let bob_msg = Message::load_from_db(&bob, *msg.msg_ids.first().unwrap()).await?; assert_eq!(bob_msg.chat_id, bob_chat_id); assert_eq!(bob_msg.viewtype, Viewtype::Image); + assert_eq!(bob_msg.has_location(), false); + + let bob_locations = get_range(&bob, None, None, 0, 0).await?; + assert_eq!(bob_locations.len(), 1); Ok(()) } diff --git a/src/message.rs b/src/message.rs index e4739bf85..408d0a80c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -655,9 +655,11 @@ impl Message { Ok(()) } - /// Check if a message has a location bound to it. - /// These messages are also returned by get_locations() - /// and the UI may decide to display a special icon beside such messages, + /// Check if a message has a POI location bound to it. + /// These locations are also returned by [`location::get_range()`]. + /// The UI may decide to display a special icon beside such messages. + /// + /// [`location::get_range()`]: crate::location::get_range pub fn has_location(&self) -> bool { self.location_id != 0 } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 67eb19b31..31bf9fb1c 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1669,11 +1669,10 @@ async fn save_locations( if let Some(addr) = &location_kml.addr { let contact = Contact::get_by_id(context, from_id).await?; if contact.get_addr().to_lowercase() == addr.to_lowercase() { - if let Some(newest_location_id) = - location::save(context, chat_id, from_id, &location_kml.locations, false) - .await? + if location::save(context, chat_id, from_id, &location_kml.locations, false) + .await? + .is_some() { - location::set_msg_location_id(context, msg_id, newest_location_id).await?; send_event = true; } } else {