Return Vec<dc_location> from dc_get_locations

This commit is contained in:
Alexander Krotov
2019-08-15 20:29:36 +03:00
committed by holger krekel
parent d4dfc5443c
commit 37622af55a
3 changed files with 20 additions and 28 deletions

View File

@@ -1035,13 +1035,14 @@ pub unsafe extern "C" fn dc_get_locations(
assert!(!context.is_null());
let context = &*context;
dc_location::dc_get_locations(
let res = dc_location::dc_get_locations(
context,
chat_id,
contact_id,
timestamp_begin as i64,
timestamp_end as i64,
)
);
dc_array_t::from(res).into_raw()
}
#[no_mangle]

View File

@@ -839,36 +839,28 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
}
"getlocations" => {
let contact_id = arg1.parse().unwrap_or_default();
let loc = dc_get_locations(context, dc_chat_get_id(sel_chat), contact_id, 0, 0);
let mut j = 0;
while j < dc_array_get_cnt(loc) {
let timestr_0 = dc_timestamp_to_str(dc_array_get_timestamp(loc, j as size_t));
let marker = dc_array_get_marker(loc, j as size_t);
let locations = dc_get_locations(context, dc_chat_get_id(sel_chat), contact_id, 0, 0);
let default_marker = "-".to_string();
for location in &locations {
let marker = location.marker.as_ref().unwrap_or(&default_marker);
info!(
context,
0,
"Loc#{}: {}: lat={} lng={} acc={} Chat#{} Contact#{} Msg#{} {}",
dc_array_get_id(loc, j as size_t),
&timestr_0,
dc_array_get_latitude(loc, j as size_t),
dc_array_get_longitude(loc, j as size_t),
dc_array_get_accuracy(loc, j as size_t),
dc_array_get_chat_id(loc, j as size_t),
dc_array_get_contact_id(loc, j as size_t),
dc_array_get_msg_id(loc, j as size_t),
if !marker.is_null() {
as_str(marker)
} else {
"-"
},
location.location_id,
dc_timestamp_to_str(location.timestamp),
location.latitude,
location.longitude,
location.accuracy,
location.chat_id,
location.contact_id,
location.msg_id,
marker
);
free(marker as *mut libc::c_void);
j += 1
}
if dc_array_get_cnt(loc) == 0 {
if locations.is_empty() {
info!(context, 0, "No locations.");
}
dc_array_unref(loc);
}
"sendlocations" => {
ensure!(!sel_chat.is_null(), "No chat selected.");

View File

@@ -3,7 +3,6 @@ use std::ffi::CString;
use crate::constants::Event;
use crate::constants::*;
use crate::context::*;
use crate::dc_array::*;
use crate::dc_chat::*;
use crate::dc_job::*;
use crate::dc_msg::*;
@@ -201,7 +200,7 @@ pub fn dc_get_locations(
contact_id: uint32_t,
timestamp_from: i64,
mut timestamp_to: i64,
) -> *mut dc_array_t {
) -> Vec<dc_location> {
if timestamp_to == 0 {
timestamp_to = time() + 10;
}
@@ -252,10 +251,10 @@ pub fn dc_get_locations(
for location in locations {
ret.push(location?);
}
Ok(dc_array_t::from(ret).into_raw())
Ok(ret)
},
)
.unwrap_or_else(|_| std::ptr::null_mut())
.unwrap_or_default()
}
fn is_marker(txt: &str) -> bool {