mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
feat: do not add location markers to messages with non-POI location
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -35,6 +35,10 @@ pub struct MessageObject {
|
||||
parent_id: Option<u32>,
|
||||
|
||||
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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user