diff --git a/src/main.rs b/src/main.rs index d12290f..eff5244 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,8 +84,12 @@ async fn tokio_main() -> Result<(), AppError<()>> { let theme_config = THEME_CONFIG.clone(); tracing::info!("Theme config: {:?}", theme_config); - let telegram_config = TELEGRAM_CONFIG.clone(); + let mut telegram_config = TELEGRAM_CONFIG.clone(); tracing::info!("Telegram config: {:?}", telegram_config); + // This is used to disable the message database when running the application as a CLI. + // This is done to avoid that deleting a message other application in + // a chats causes the `--send-message` to resend the messages that were deleted. + telegram_config.use_message_database = std::env::args().count() <= 1; let tg_context = TgContext::default(); tracing::info!("Telegram context: {:?}", tg_context); diff --git a/src/run.rs b/src/run.rs index ac83af2..165a49f 100644 --- a/src/run.rs +++ b/src/run.rs @@ -332,6 +332,8 @@ async fn handle_cli(app_context: Arc, tg_backend: &mut TgBackend) -> return HandleCliOutcome::Quit; } if let Some(chat) = app_context.cli_args().telegram_cli().send_message() { + futures::join!(tg_backend.load_all_chats()); + let [chat_name, message_text] = chat.as_slice() else { tracing::error!("Invalid number of arguments for send message"); println!("Invalid number of arguments for send message"); @@ -369,7 +371,6 @@ async fn handle_cli(app_context: Arc, tg_backend: &mut TgBackend) -> return HandleCliOutcome::Quit; } } - // std::thread::sleep(std::time::Duration::from_secs(1)); tracing::info!( "Sent message {} to chat_name {} ({})", diff --git a/src/tg/tg_backend.rs b/src/tg/tg_backend.rs index 8abcf03..e7df468 100644 --- a/src/tg/tg_backend.rs +++ b/src/tg/tg_backend.rs @@ -76,6 +76,12 @@ impl TgBackend { } } + pub async fn load_all_chats(&mut self) { + while !self.full_chats_list { + self.load_chats(ChatList::Main, 50).await; + } + } + pub async fn search_chats( &self, username: String,