diff --git a/src/chat.rs b/src/chat.rs index 101ff3f1c7..547e537ff6 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2700,7 +2700,7 @@ async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) - } if msg.param.exists(Param::SetLatitude) { - context.emit_event(EventType::LocationChanged(Some(ContactId::SELF))); + context.emit_location_changed(Some(ContactId::SELF)).await?; } context.scheduler.interrupt_smtp().await; diff --git a/src/context.rs b/src/context.rs index 5b6e3c8563..baa28c0406 100644 --- a/src/context.rs +++ b/src/context.rs @@ -600,6 +600,23 @@ impl Context { self.emit_event(EventType::IncomingMsg { chat_id, msg_id }); } + /// Emits an LocationChanged event and a WebxdcStatusUpdate in case there is a maps integration + pub async fn emit_location_changed(&self, contact_id: Option) -> Result<()> { + self.emit_event(EventType::LocationChanged(contact_id)); + + if let Some(msg_id) = self + .get_config_parsed::(Config::WebxdcIntegration) + .await? + { + self.emit_event(EventType::WebxdcStatusUpdate { + msg_id: MsgId::new(msg_id), + status_update_serial: Default::default(), + }) + } + + Ok(()) + } + /// Returns a receiver for emitted events. /// /// Multiple emitters can be created, but note that in this case each emitted event will diff --git a/src/location.rs b/src/location.rs index d5a2337c10..923fd26a55 100644 --- a/src/location.rs +++ b/src/location.rs @@ -366,7 +366,7 @@ pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64 continue_streaming = true; } if continue_streaming { - context.emit_event(EventType::LocationChanged(Some(ContactId::SELF))); + context.emit_location_changed(Some(ContactId::SELF)).await?; }; Ok(continue_streaming) @@ -456,7 +456,7 @@ fn is_marker(txt: &str) -> bool { /// Deletes all locations from the database. pub async fn delete_all(context: &Context) -> Result<()> { context.sql.execute("DELETE FROM locations;", ()).await?; - context.emit_event(EventType::LocationChanged(None)); + context.emit_location_changed(None).await?; Ok(()) } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 512302602f..c9ef699026 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1688,7 +1688,7 @@ async fn save_locations( } } if send_event { - context.emit_event(EventType::LocationChanged(Some(from_id))); + context.emit_location_changed(Some(from_id)).await?; } Ok(()) } diff --git a/src/webxdc/maps_integration.rs b/src/webxdc/maps_integration.rs index daf8a0f20b..3035c4effc 100644 --- a/src/webxdc/maps_integration.rs +++ b/src/webxdc/maps_integration.rs @@ -31,10 +31,6 @@ //! label: "" // used for POI only //! } //! ``` -//! -//! For messenger implementors adding support for these Webxdc: -//! New locations, are announced by `DC_EVENT_LOCATION_CHANGED` -//! (not by `DC_EVENT_WEBXDC_STATUS_UPDATE`). use crate::{chat, location}; use std::collections::{hash_map, HashMap}; @@ -174,10 +170,10 @@ mod tests { use crate::chat::{create_group_chat, ChatId, ProtectionStatus}; use crate::chatlist::Chatlist; use crate::contact::Contact; - use crate::location; use crate::message::Message; use crate::test_utils::TestContext; use crate::webxdc::StatusUpdateSerial; + use crate::{location, EventType}; use anyhow::Result; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -212,6 +208,9 @@ mod tests { "descr", ) .await?; + t.evtracker + .get_matching(|evt| matches!(evt, EventType::WebxdcStatusUpdate { .. })) + .await; let updates = t .get_webxdc_status_updates(integration_id, StatusUpdateSerial(0)) .await?;