Skip to content

Commit

Permalink
fix: start ephemeral timer for all archived chats if archived chat is…
Browse files Browse the repository at this point in the history
… noticed
  • Loading branch information
link2xt committed Dec 24, 2024
1 parent 5772284 commit 60519bd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 30 additions & 0 deletions src/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}
}

0 comments on commit 60519bd

Please sign in to comment.