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) }