mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 13:56:30 +03:00
refactor(location): make location on the kml object not optional
This commit is contained in:
@@ -938,15 +938,13 @@ unsafe fn save_locations(
|
|||||||
let mut send_event = false;
|
let mut send_event = false;
|
||||||
|
|
||||||
if !mime_parser.message_kml.is_none() && chat_id > DC_CHAT_ID_LAST_SPECIAL as libc::c_uint {
|
if !mime_parser.message_kml.is_none() && chat_id > DC_CHAT_ID_LAST_SPECIAL as libc::c_uint {
|
||||||
if let Some(ref locations) = mime_parser.message_kml.as_ref().unwrap().locations {
|
let locations = &mime_parser.message_kml.as_ref().unwrap().locations;
|
||||||
let newest_location_id =
|
let newest_location_id =
|
||||||
location::save(context, chat_id, from_id, locations, 1).unwrap_or_default();
|
location::save(context, chat_id, from_id, locations, 1).unwrap_or_default();
|
||||||
if 0 != newest_location_id && 0 == hidden {
|
if 0 != newest_location_id && 0 == hidden {
|
||||||
if location::set_msg_location_id(context, insert_msg_id, newest_location_id).is_ok()
|
if location::set_msg_location_id(context, insert_msg_id, newest_location_id).is_ok() {
|
||||||
{
|
location_id_written = true;
|
||||||
location_id_written = true;
|
send_event = true;
|
||||||
send_event = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -957,23 +955,19 @@ unsafe fn save_locations(
|
|||||||
if !contact.get_addr().is_empty()
|
if !contact.get_addr().is_empty()
|
||||||
&& contact.get_addr().to_lowercase() == addr.to_lowercase()
|
&& contact.get_addr().to_lowercase() == addr.to_lowercase()
|
||||||
{
|
{
|
||||||
if let Some(ref locations) =
|
let locations = &mime_parser.location_kml.as_ref().unwrap().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();
|
||||||
let newest_location_id =
|
if newest_location_id != 0 && hidden == 0 && !location_id_written {
|
||||||
location::save(context, chat_id, from_id, locations, 0)
|
if let Err(err) = location::set_msg_location_id(
|
||||||
.unwrap_or_default();
|
context,
|
||||||
if newest_location_id != 0 && hidden == 0 && !location_id_written {
|
insert_msg_id,
|
||||||
if let Err(err) = location::set_msg_location_id(
|
newest_location_id,
|
||||||
context,
|
) {
|
||||||
insert_msg_id,
|
error!(context, 0, "Failed to set msg_location_id: {:?}", err);
|
||||||
newest_location_id,
|
|
||||||
) {
|
|
||||||
error!(context, 0, "Failed to set msg_location_id: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
send_event = true;
|
|
||||||
}
|
}
|
||||||
|
send_event = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl Location {
|
|||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Kml {
|
pub struct Kml {
|
||||||
pub addr: Option<String>,
|
pub addr: Option<String>,
|
||||||
pub locations: Option<Vec<Location>>,
|
pub locations: Vec<Location>,
|
||||||
tag: KmlTag,
|
tag: KmlTag,
|
||||||
pub curr: Location,
|
pub curr: Location,
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ impl Kml {
|
|||||||
reader.trim_text(true);
|
reader.trim_text(true);
|
||||||
|
|
||||||
let mut kml = Kml::new();
|
let mut kml = Kml::new();
|
||||||
kml.locations = Some(Vec::with_capacity(100));
|
kml.locations = Vec::with_capacity(100);
|
||||||
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
@@ -142,9 +142,8 @@ impl Kml {
|
|||||||
&& 0. != self.curr.latitude
|
&& 0. != self.curr.latitude
|
||||||
&& 0. != self.curr.longitude
|
&& 0. != self.curr.longitude
|
||||||
{
|
{
|
||||||
if let Some(ref mut locations) = self.locations {
|
self.locations
|
||||||
locations.push(std::mem::replace(&mut self.curr, Location::new()));
|
.push(std::mem::replace(&mut self.curr, Location::new()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.tag = KmlTag::UNDEFINED;
|
self.tag = KmlTag::UNDEFINED;
|
||||||
};
|
};
|
||||||
@@ -675,7 +674,7 @@ mod tests {
|
|||||||
assert!(kml.addr.is_some());
|
assert!(kml.addr.is_some());
|
||||||
assert_eq!(kml.addr.as_ref().unwrap(), "user@example.org",);
|
assert_eq!(kml.addr.as_ref().unwrap(), "user@example.org",);
|
||||||
|
|
||||||
let locations_ref = &kml.locations.as_ref().unwrap();
|
let locations_ref = &kml.locations;
|
||||||
assert_eq!(locations_ref.len(), 2);
|
assert_eq!(locations_ref.len(), 2);
|
||||||
|
|
||||||
assert!(locations_ref[0].latitude > 53.6f64);
|
assert!(locations_ref[0].latitude > 53.6f64);
|
||||||
|
|||||||
Reference in New Issue
Block a user