mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
fix and streamline location-outgoing pipeline
This commit is contained in:
@@ -823,9 +823,12 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
ac1._evlogger.consume_events()
|
ac1._evlogger.consume_events()
|
||||||
ac2._evlogger.consume_events()
|
ac2._evlogger.consume_events()
|
||||||
|
|
||||||
lp.sec("ac1: enable location sending in chat")
|
lp.sec("ac1: enable location sending in chat")
|
||||||
chat1.enable_sending_locations(seconds=100)
|
chat1.enable_sending_locations(seconds=100)
|
||||||
assert chat1.is_sending_locations()
|
assert chat1.is_sending_locations()
|
||||||
|
|
||||||
|
lp.sec("ac1: setting location")
|
||||||
ac1.set_location(latitude=1.0, longitude=2.0)
|
ac1.set_location(latitude=1.0, longitude=2.0)
|
||||||
ac1._evlogger.get_matching("DC_EVENT_LOCATION_CHANGED")
|
ac1._evlogger.get_matching("DC_EVENT_LOCATION_CHANGED")
|
||||||
chat1.send_text("hello")
|
chat1.send_text("hello")
|
||||||
|
|||||||
@@ -369,9 +369,6 @@ pub fn delete_all(context: &Context) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_kml(context: &Context, chat_id: u32) -> Result<(String, u32), Error> {
|
pub fn get_kml(context: &Context, chat_id: u32) -> Result<(String, u32), Error> {
|
||||||
let now = time();
|
|
||||||
let mut location_count = 0;
|
|
||||||
let mut ret = String::new();
|
|
||||||
let mut last_added_location_id = 0;
|
let mut last_added_location_id = 0;
|
||||||
|
|
||||||
let self_addr = context
|
let self_addr = context
|
||||||
@@ -388,14 +385,17 @@ pub fn get_kml(context: &Context, chat_id: u32) -> Result<(String, u32), Error>
|
|||||||
Ok((send_begin, send_until, last_sent))
|
Ok((send_begin, send_until, last_sent))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !(locations_send_begin == 0 || now > locations_send_until) {
|
let now = time();
|
||||||
|
let mut location_count = 0;
|
||||||
|
let mut ret = String::new();
|
||||||
|
if locations_send_begin != 0 && now <= locations_send_until {
|
||||||
ret += &format!(
|
ret += &format!(
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document addr=\"{}\">\n",
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document addr=\"{}\">\n",
|
||||||
self_addr,
|
self_addr,
|
||||||
);
|
);
|
||||||
|
|
||||||
context.sql.query_map(
|
context.sql.query_map(
|
||||||
"SELECT id, latitude, longitude, accuracy, timestamp\
|
"SELECT id, latitude, longitude, accuracy, timestamp \
|
||||||
FROM locations WHERE from_id=? \
|
FROM locations WHERE from_id=? \
|
||||||
AND timestamp>=? \
|
AND timestamp>=? \
|
||||||
AND (timestamp>=? OR timestamp=(SELECT MAX(timestamp) FROM locations WHERE from_id=?)) \
|
AND (timestamp>=? OR timestamp=(SELECT MAX(timestamp) FROM locations WHERE from_id=?)) \
|
||||||
@@ -416,7 +416,7 @@ pub fn get_kml(context: &Context, chat_id: u32) -> Result<(String, u32), Error>
|
|||||||
for row in rows {
|
for row in rows {
|
||||||
let (location_id, latitude, longitude, accuracy, timestamp) = row?;
|
let (location_id, latitude, longitude, accuracy, timestamp) = row?;
|
||||||
ret += &format!(
|
ret += &format!(
|
||||||
"<Placemark><Timestamp><when>{}</when></Timestamp><Point><coordinates accuracy=\"{}\">{},{}</coordinates></Point></Placemark>\n\x00",
|
"<Placemark><Timestamp><when>{}</when></Timestamp><Point><coordinates accuracy=\"{}\">{},{}</coordinates></Point></Placemark>\n",
|
||||||
timestamp,
|
timestamp,
|
||||||
accuracy,
|
accuracy,
|
||||||
longitude,
|
longitude,
|
||||||
@@ -428,10 +428,10 @@ pub fn get_kml(context: &Context, chat_id: u32) -> Result<(String, u32), Error>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
)?;
|
)?;
|
||||||
|
ret += "</Document>\n</kml>";
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure!(location_count > 0, "No locations processed");
|
ensure!(location_count > 0, "No locations processed");
|
||||||
ret += "</Document>\n</kml>";
|
|
||||||
|
|
||||||
Ok((ret, last_added_location_id))
|
Ok((ret, last_added_location_id))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -484,6 +484,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
if !meta_part.is_null() {
|
if !meta_part.is_null() {
|
||||||
mailmime_smart_add_part(message, meta_part);
|
mailmime_smart_add_part(message, meta_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.msg.param.exists(Param::SetLatitude) {
|
if self.msg.param.exists(Param::SetLatitude) {
|
||||||
let param = &self.msg.param;
|
let param = &self.msg.param;
|
||||||
let kml_file = location::get_message_kml(
|
let kml_file = location::get_message_kml(
|
||||||
@@ -500,18 +501,25 @@ impl<'a> MimeFactory<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if location::is_sending_locations_to_chat(context, self.msg.chat_id) {
|
if location::is_sending_locations_to_chat(context, self.msg.chat_id) {
|
||||||
if let Ok((kml_file, last_added_location_id)) =
|
match location::get_kml(context, self.msg.chat_id) {
|
||||||
location::get_kml(context, self.msg.chat_id)
|
Ok((kml_content, last_added_location_id)) => {
|
||||||
{
|
info!(
|
||||||
wrapmime::add_filename_part(
|
context,
|
||||||
message,
|
"adding location.kml to mime message: {}", kml_content
|
||||||
"location.kml",
|
);
|
||||||
"application/vnd.google-earth.kml+xml",
|
wrapmime::add_filename_part(
|
||||||
&kml_file,
|
message,
|
||||||
)?;
|
"location.kml",
|
||||||
if !self.msg.param.exists(Param::SetLatitude) {
|
"application/vnd.google-earth.kml+xml",
|
||||||
// otherwise, the independent location is already filed
|
&kml_content,
|
||||||
self.out_last_added_location_id = last_added_location_id;
|
)?;
|
||||||
|
if !self.msg.param.exists(Param::SetLatitude) {
|
||||||
|
// otherwise, the independent location is already filed
|
||||||
|
self.out_last_added_location_id = last_added_location_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
warn!(context, "mimefactory: could not get location: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user