From f49588e64ea0019ea621fcda9861aba7a05ccace Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 27 Apr 2024 17:58:27 +0000 Subject: [PATCH] fix: interrupt location loop when new location is stored Otherwise location-only messages that should be sent every 60 seconds are never sent because location loop waits until the end of location streaming and is only interrupted by location streaming ending in other chats or being enabled in other chats. --- python/tests/test_1_online.py | 9 +++++---- src/location.rs | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 3fc8823a5..318262f3d 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -2036,14 +2036,15 @@ def test_send_receive_locations(acfactory, lp): assert chat1.is_sending_locations() ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") + # Wait for "enabled location streaming" message. + ac2._evtracker.wait_next_incoming_message() + + # First location is sent immediately as a location-only message. ac1.set_location(latitude=2.0, longitude=3.0, accuracy=0.5) ac1._evtracker.get_matching("DC_EVENT_LOCATION_CHANGED") - chat1.send_text("🍞") ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") lp.sec("ac2: wait for incoming location message") - - # currently core emits location changed before event_incoming message ac2._evtracker.get_matching("DC_EVENT_LOCATION_CHANGED") locations = chat2.get_locations() @@ -2052,7 +2053,7 @@ def test_send_receive_locations(acfactory, lp): assert locations[0].longitude == 3.0 assert locations[0].accuracy == 0.5 assert locations[0].timestamp > now - assert locations[0].marker == "🍞" + assert locations[0].marker is None contact = ac2.create_contact(ac1) locations2 = chat2.get_locations(contact=contact) diff --git a/src/location.rs b/src/location.rs index a934cd5be..32c56b2cc 100644 --- a/src/location.rs +++ b/src/location.rs @@ -350,6 +350,7 @@ pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64 ) .await?; + let mut stored_location = false; for chat_id in chats { context.sql.execute( "INSERT INTO locations \ @@ -362,6 +363,7 @@ pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64 chat_id, ContactId::SELF, )).await.context("Failed to store location")?; + stored_location = true; info!(context, "Stored location for chat {chat_id}."); continue_streaming = true; @@ -369,6 +371,10 @@ pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64 if continue_streaming { context.emit_location_changed(Some(ContactId::SELF)).await?; }; + if stored_location { + // Interrupt location loop so it may send a location-only message. + context.scheduler.interrupt_location().await; + } Ok(continue_streaming) }