refactor(location): more rusty api

This commit is contained in:
dignifiedquire
2019-08-26 21:29:40 +02:00
parent 23d49560bf
commit d25d839d6a
7 changed files with 266 additions and 260 deletions

View File

@@ -21,7 +21,7 @@ use crate::dc_strencode::*;
use crate::dc_tools::*;
use crate::error::Result;
use crate::job::*;
use crate::location::*;
use crate::location;
use crate::message::*;
use crate::param::*;
use crate::peerstate::*;
@@ -938,17 +938,16 @@ unsafe fn save_locations(
let mut send_event = false;
if !mime_parser.message_kml.is_none() && chat_id > DC_CHAT_ID_LAST_SPECIAL as libc::c_uint {
let newest_location_id: uint32_t = dc_save_locations(
context,
chat_id,
from_id,
&mime_parser.message_kml.as_ref().unwrap().locations,
1,
);
if 0 != newest_location_id && 0 == hidden {
dc_set_msg_location_id(context, insert_msg_id, newest_location_id);
location_id_written = true;
send_event = true;
if let Some(ref locations) = mime_parser.message_kml.as_ref().unwrap().locations {
let newest_location_id =
location::save(context, chat_id, from_id, locations, 1).unwrap_or_default();
if 0 != newest_location_id && 0 == hidden {
if location::set_msg_location_id(context, insert_msg_id, newest_location_id).is_ok()
{
location_id_written = true;
send_event = true;
}
}
}
}
@@ -958,17 +957,23 @@ unsafe fn save_locations(
if !contact.get_addr().is_empty()
&& contact.get_addr().to_lowercase() == addr.to_lowercase()
{
let newest_location_id = dc_save_locations(
context,
chat_id,
from_id,
&mime_parser.location_kml.as_ref().unwrap().locations,
0,
);
if newest_location_id != 0 && hidden == 0 && !location_id_written {
dc_set_msg_location_id(context, insert_msg_id, newest_location_id);
if let Some(ref locations) =
mime_parser.location_kml.as_ref().unwrap().locations
{
let newest_location_id =
location::save(context, chat_id, from_id, locations, 0)
.unwrap_or_default();
if newest_location_id != 0 && hidden == 0 && !location_id_written {
if let Err(err) = location::set_msg_location_id(
context,
insert_msg_id,
newest_location_id,
) {
error!(context, 0, "Failed to set msg_location_id: {:?}", err);
}
}
send_event = true;
}
send_event = true;
}
}
}