Skip to content

Commit

Permalink
fix and rename dc_msg_get_location to dc_msg_get_poi_location
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Dec 21, 2024
1 parent cc62019 commit ba15bba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4887,7 +4887,7 @@ dc_msg_t* dc_msg_get_parent (const dc_msg_t* msg);
void dc_msg_force_plaintext (dc_msg_t* msg);

void dc_msg_force_sticker (dc_msg_t* msg);
char* dc_msg_get_location (dc_msg_t* msg);
char* dc_msg_get_poi_location (dc_msg_t* msg);

/**
* @class dc_contact_t
Expand Down
8 changes: 2 additions & 6 deletions deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3254,17 +3254,13 @@ pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 {
}

#[no_mangle]
pub unsafe extern "C" fn dc_msg_get_location(msg: *mut dc_msg_t) -> *mut libc::c_char {
pub unsafe extern "C" fn dc_msg_get_poi_location(msg: *mut dc_msg_t) -> *mut libc::c_char {
if msg.is_null() {
eprintln!("ignoring careless call to dc_msg_get_location_str()");
return "".strdup();
}
let ffi_msg = &*msg;
if ffi_msg.message.has_location() {
ffi_msg.message.get_location().strdup()
} else {
"".strdup()
}
block_on(ffi_msg.message.get_poi_location(&*ffi_msg.context)).strdup()
}

#[no_mangle]
Expand Down
13 changes: 13 additions & 0 deletions src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,19 @@ pub(crate) async fn delete_poi_location(context: &Context, location_id: u32) ->
Ok(())
}

pub(crate) async fn get_poi_location(context: &Context, location_id: u32) -> Result<(f64, f64)> {
context
.sql
.query_row(
"SELECT latitude, longitude FROM locations WHERE independent=1 AND id=?",
(location_id as i32,),
|row| {
Ok((row.get(0)?, row.get(1)?))
},
)
.await
}

/// Deletes POI locations that don't have corresponding message anymore.
pub(crate) async fn delete_orphaned_poi_locations(context: &Context) -> Result<()> {
context.sql.execute("
Expand Down
13 changes: 9 additions & 4 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::ephemeral::{start_ephemeral_timers_msgids, Timer as EphemeralTimer};
use crate::events::EventType;
use crate::imap::markseen_on_imap_table;
use crate::location::delete_poi_location;
use crate::location::get_poi_location;
use crate::mimeparser::{parse_message_id, SystemMessage};
use crate::param::{Param, Params};
use crate::pgp::split_armored_data;
Expand Down Expand Up @@ -714,10 +715,14 @@ impl Message {
}

/// Returns the location metadata associated to this message as a string "latitude,longitude".
pub fn get_location(&self) -> String {
let latitude = self.param.get(Param::SetLatitude).unwrap_or_default();
let longitude = self.param.get(Param::SetLongitude).unwrap_or_default();
format!("{latitude},{longitude}")
pub async fn get_poi_location(&self, context: &Context) -> String {
if !self.has_location() {
"".to_string()
} else if let Ok((latitude, longitude)) = get_poi_location(context, self.location_id).await {
format!("{latitude},{longitude}")
} else {
"".to_string()
}
}

/// Set any location that should be bound to the message object.
Expand Down

0 comments on commit ba15bba

Please sign in to comment.