Skip to content

Commit

Permalink
emit DC_EVENT_WEBXDC_STATUS_UPDATE together with DC_EVENT_LOCATION_CH…
Browse files Browse the repository at this point in the history
…ANGED
  • Loading branch information
r10s committed Apr 14, 2024
1 parent 88b48f0 commit 699093f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContactId>) -> Result<()> {
self.emit_event(EventType::LocationChanged(contact_id));

if let Some(msg_id) = self
.get_config_parsed::<u32>(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
Expand Down
4 changes: 2 additions & 2 deletions src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
9 changes: 4 additions & 5 deletions src/webxdc/maps_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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?;
Expand Down

0 comments on commit 699093f

Please sign in to comment.