From df19bc742c26d0df0221133ff83e77540f19ca6b Mon Sep 17 00:00:00 2001 From: Mikhail Kilin Date: Sun, 22 Feb 2026 16:19:04 +0300 Subject: [PATCH] fix: add photo_download_rx channel and fix account switcher nav tests Add UnboundedReceiver for background photo downloads to App state, reset it on close_chat. Fix account_switcher tests to navigate past all accounts dynamically instead of assuming single account. Co-Authored-By: Claude Opus 4.6 --- src/app/methods/navigation.rs | 5 +++++ src/app/mod.rs | 8 +++++++- tests/account_switcher.rs | 24 +++++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/app/methods/navigation.rs b/src/app/methods/navigation.rs index 8099550..da4581c 100644 --- a/src/app/methods/navigation.rs +++ b/src/app/methods/navigation.rs @@ -83,6 +83,11 @@ impl NavigationMethods for App { self.message_scroll_offset = 0; self.last_typing_sent = None; self.pending_chat_init = None; + // Останавливаем фоновую загрузку фото (drop receiver) + #[cfg(feature = "images")] + { + self.photo_download_rx = None; + } // Сбрасываем состояние чата в нормальный режим self.chat_state = ChatState::Normal; self.input_mode = InputMode::Normal; diff --git a/src/app/mod.rs b/src/app/mod.rs index c510a86..8f94c73 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -128,8 +128,12 @@ pub struct App { pub current_account_name: String, /// Pending account switch: (account_name, db_path) pub pending_account_switch: Option<(String, PathBuf)>, - /// Pending background chat init (reply info, pinned, photos) after fast open + /// Pending background chat init (reply info, pinned) after fast open pub pending_chat_init: Option, + /// Receiver for background photo downloads (file_id, result path) + #[cfg(feature = "images")] + pub photo_download_rx: + Option)>>, // Voice playback /// Аудиопроигрыватель для голосовых сообщений (rodio) pub audio_player: Option, @@ -198,6 +202,8 @@ impl App { pending_account_switch: None, pending_chat_init: None, #[cfg(feature = "images")] + photo_download_rx: None, + #[cfg(feature = "images")] image_cache, #[cfg(feature = "images")] inline_image_renderer, diff --git a/tests/account_switcher.rs b/tests/account_switcher.rs index 16522f0..68f426f 100644 --- a/tests/account_switcher.rs +++ b/tests/account_switcher.rs @@ -47,8 +47,15 @@ fn test_account_switcher_navigate_down() { let mut app = TestAppBuilder::new().build(); app.open_account_switcher(); - // Initially at 0, navigate down to "Add account" item - app.account_switcher_select_next(); + let num_accounts = match &app.account_switcher { + Some(AccountSwitcherState::SelectAccount { accounts, .. }) => accounts.len(), + _ => panic!("Expected SelectAccount state"), + }; + + // Navigate down past all accounts to "Add account" item + for _ in 0..num_accounts { + app.account_switcher_select_next(); + } match &app.account_switcher { Some(AccountSwitcherState::SelectAccount { @@ -56,7 +63,7 @@ fn test_account_switcher_navigate_down() { accounts, .. }) => { - // Should be at index 1 (the "Add account" item, since default config has 1 account) + // Should be at the "Add account" item (index == accounts.len()) assert_eq!(*selected_index, accounts.len()); } _ => panic!("Expected SelectAccount state"), @@ -116,8 +123,15 @@ fn test_confirm_add_account_transitions_to_add_state() { let mut app = TestAppBuilder::new().build(); app.open_account_switcher(); - // Navigate to "+ Add account" - app.account_switcher_select_next(); + let num_accounts = match &app.account_switcher { + Some(AccountSwitcherState::SelectAccount { accounts, .. }) => accounts.len(), + _ => panic!("Expected SelectAccount state"), + }; + + // Navigate past all accounts to "+ Add account" + for _ in 0..num_accounts { + app.account_switcher_select_next(); + } // Confirm should transition to AddAccount app.account_switcher_confirm();