mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
address @link2xt comments
This commit is contained in:
@@ -404,15 +404,14 @@ class Chat(object):
|
||||
contact_id = contact.id
|
||||
|
||||
dc_array = lib.dc_get_locations(self._dc_context, self.id, contact_id, time_from, time_to)
|
||||
locations = []
|
||||
for i in range(0, lib.dc_array_get_cnt(dc_array)):
|
||||
locations.append(Location(
|
||||
return [
|
||||
Location(
|
||||
latitude=lib.dc_array_get_latitude(dc_array, i),
|
||||
longitude=lib.dc_array_get_longitude(dc_array, i),
|
||||
accuracy=lib.dc_array_get_accuracy(dc_array, i),
|
||||
timestamp=datetime.utcfromtimestamp(lib.dc_array_get_timestamp(dc_array, i)),
|
||||
))
|
||||
return locations
|
||||
timestamp=datetime.utcfromtimestamp(lib.dc_array_get_timestamp(dc_array, i)))
|
||||
for i in range(lib.dc_array_get_cnt(dc_array))
|
||||
]
|
||||
|
||||
|
||||
class Location:
|
||||
|
||||
@@ -843,7 +843,7 @@ class TestOnlineAccount:
|
||||
ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG") # text message with location
|
||||
|
||||
locations = chat2.get_locations()
|
||||
assert len(locations) >= 1
|
||||
assert len(locations) == 1
|
||||
assert locations[0].latitude == 2.0
|
||||
assert locations[0].longitude == 3.0
|
||||
assert locations[0].accuracy == 0.5
|
||||
@@ -851,7 +851,7 @@ class TestOnlineAccount:
|
||||
|
||||
contact = ac2.create_contact(ac1.get_config("addr"))
|
||||
locations2 = chat2.get_locations(contact=contact)
|
||||
assert len(locations2) >= 1
|
||||
assert len(locations2) == 1
|
||||
assert locations2 == locations
|
||||
|
||||
contact = ac2.create_contact("nonexisting@example.org")
|
||||
|
||||
@@ -840,19 +840,12 @@ fn save_locations(
|
||||
insert_msg_id: MsgId,
|
||||
hidden: i32,
|
||||
) {
|
||||
if chat_id <= DC_CHAT_ID_LAST_SPECIAL as libc::c_uint {
|
||||
if chat_id <= DC_CHAT_ID_LAST_SPECIAL {
|
||||
return ();
|
||||
}
|
||||
let mut location_id_written = false;
|
||||
let mut send_event = false;
|
||||
|
||||
info!(
|
||||
context,
|
||||
"saving locations chat_id={} insert_msg_id={}",
|
||||
chat_id,
|
||||
insert_msg_id.to_u32()
|
||||
);
|
||||
|
||||
if mime_parser.message_kml.is_some() {
|
||||
let locations = &mime_parser.message_kml.as_ref().unwrap().locations;
|
||||
let newest_location_id =
|
||||
|
||||
@@ -63,7 +63,7 @@ impl Kml {
|
||||
}
|
||||
|
||||
pub fn parse(context: &Context, content: &[u8]) -> Result<Self, Error> {
|
||||
ensure!(content.len() <= (1024 * 1024), "kml-file too large");
|
||||
ensure!(content.len() <= 1024 * 1024, "kml-file is too large");
|
||||
|
||||
let to_parse = String::from_utf8_lossy(content);
|
||||
let mut reader = quick_xml::Reader::from_str(&to_parse);
|
||||
@@ -669,9 +669,9 @@ mod tests {
|
||||
let context = dummy_context();
|
||||
|
||||
let xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document addr=\"user@example.org\">\n<Placemark><Timestamp><when>2019-03-06T21:09:57Z</when></Timestamp><Point><coordinates accuracy=\"32.000000\">9.423110,53.790302</coordinates></Point></Placemark>\n<PlaceMARK>\n<Timestamp><WHEN > \n\t2018-12-13T22:11:12Z\t</WHEN></Timestamp><Point><coordinates aCCuracy=\"2.500000\"> 19.423110 \t , \n 63.790302\n </coordinates></Point></PlaceMARK>\n</Document>\n</kml>";
|
||||
b"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document addr=\"user@example.org\">\n<Placemark><Timestamp><when>2019-03-06T21:09:57Z</when></Timestamp><Point><coordinates accuracy=\"32.000000\">9.423110,53.790302</coordinates></Point></Placemark>\n<PlaceMARK>\n<Timestamp><WHEN > \n\t2018-12-13T22:11:12Z\t</WHEN></Timestamp><Point><coordinates aCCuracy=\"2.500000\"> 19.423110 \t , \n 63.790302\n </coordinates></Point></PlaceMARK>\n</Document>\n</kml>";
|
||||
|
||||
let kml = Kml::parse(&context.ctx, &(xml.as_bytes())).expect("parsing failed");
|
||||
let kml = Kml::parse(&context.ctx, xml).expect("parsing failed");
|
||||
|
||||
assert!(kml.addr.is_some());
|
||||
assert_eq!(kml.addr.as_ref().unwrap(), "user@example.org",);
|
||||
|
||||
Reference in New Issue
Block a user