From 60519bdce00e206f4e0cd07449aeedff8971747d Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 24 Dec 2024 16:20:04 +0000 Subject: [PATCH] fix: start ephemeral timer for all archived chats if archived chat is noticed --- src/chat.rs | 5 +++++ src/ephemeral.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 3e9eade4b5..e13cbc8412 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -688,6 +688,10 @@ impl ChatId { }) .await?; + if visibility == ChatVisibility::Archived { + start_chat_ephemeral_timers(context, self).await?; + } + context.emit_msgs_changed_without_ids(); chatlist_events::emit_chatlist_changed(context); chatlist_events::emit_chatlist_item_changed(context, self); @@ -3266,6 +3270,7 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()> .await?; for chat_id_in_archive in chat_ids_in_archive { + start_chat_ephemeral_timers(context, chat_id_in_archive).await?; context.emit_event(EventType::MsgsNoticed(chat_id_in_archive)); chatlist_events::emit_chatlist_item_changed(context, chat_id_in_archive); } diff --git a/src/ephemeral.rs b/src/ephemeral.rs index d6e6b8af5d..14a82fdbd5 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -716,7 +716,9 @@ pub(crate) async fn start_ephemeral_timers(context: &Context) -> Result<()> { mod tests { use super::*; use crate::chat::marknoticed_chat; + use crate::chat::ChatVisibility; use crate::config::Config; + use crate::constants::DC_CHAT_ID_ARCHIVED_LINK; use crate::download::DownloadState; use crate::location; use crate::message::markseen_msgs; @@ -1468,4 +1470,32 @@ mod tests { .is_none()); Ok(()) } + + /// Tests that archiving the chat starts ephemeral timer. + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_archived_ephemeral_timer() -> 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 bob_received_message = tcm.send_recv(alice, bob, "Hello!").await; + + bob_received_message + .chat_id + .set_visibility(bob, ChatVisibility::Archived) + .await?; + SystemTime::shift(Duration::from_secs(100)); + + delete_expired_messages(bob, time()).await?; + + assert!(Message::load_from_db_optional(bob, bob_received_message.id) + .await? + .is_none()); + Ok(()) + } }