diff --git a/python/src/deltachat/chatting.py b/python/src/deltachat/chatting.py index 84f825147..3c23bf9ee 100644 --- a/python/src/deltachat/chatting.py +++ b/python/src/deltachat/chatting.py @@ -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: diff --git a/python/tests/test_account.py b/python/tests/test_account.py index d13138d70..41d197b81 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -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") diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index b8fab04d8..7f4c0bf6c 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -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 = diff --git a/src/location.rs b/src/location.rs index 555088ea9..6efef7a50 100644 --- a/src/location.rs +++ b/src/location.rs @@ -63,7 +63,7 @@ impl Kml { } pub fn parse(context: &Context, content: &[u8]) -> Result { - 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 = - "\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n"; + b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n"; - 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",);