diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 044b0eef2..7e7e9cd5a 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -686,8 +686,10 @@ mod tests { use super::*; use crate::config::Config; use crate::download::DownloadState; + use crate::location; + use crate::message::markseen_msgs; use crate::receive_imf::receive_imf; - use crate::test_utils::TestContext; + use crate::test_utils::{TestContext, TestContextManager}; use crate::timesmearing::MAX_SECONDS_TO_LEND_FROM_FUTURE; use crate::{ chat::{self, create_group_chat, send_text_msg, Chat, ChatItem, ProtectionStatus}, @@ -1364,4 +1366,44 @@ mod tests { Ok(()) } + + /// Tests that POI location is deleted when ephemeral message expires. + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_ephemeral_poi_location() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + let chat = alice.create_chat(bob).await; + + let duration = 60; + chat.id + .set_ephemeral_timer(alice, Timer::Enabled { duration }) + .await?; + let sent = alice.pop_sent_msg().await; + bob.recv_msg(&sent).await; + + let mut poi_msg = Message::new(Viewtype::Text); + poi_msg.text = "Here".to_string(); + poi_msg.set_location(10.0, 20.0); + + let alice_sent_message = alice.send_msg(chat.id, &mut poi_msg).await; + let bob_received_message = bob.recv_msg(&alice_sent_message).await; + markseen_msgs(bob, vec![bob_received_message.id]).await?; + + for account in [alice, bob] { + let locations = location::get_range(account, None, None, 0, 0).await?; + assert_eq!(locations.len(), 1); + } + + SystemTime::shift(Duration::from_secs(100)); + + for account in [alice, bob] { + delete_expired_messages(account, time()).await?; + let locations = location::get_range(account, None, None, 0, 0).await?; + assert_eq!(locations.len(), 0); + } + + Ok(()) + } }