Skip to content

Commit

Permalink
Fix deleting messages from other clients
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
Co-authored-by: Andrea Longoni <Andreal2000@users.noreply.github.com>
  • Loading branch information
FedericoBruzzone and Andreal2000 committed Jul 10, 2024
1 parent 1ba72ed commit faa4c43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ async fn handle_cli(app_context: Arc<AppContext>, 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");
Expand Down Expand Up @@ -369,7 +371,6 @@ async fn handle_cli(app_context: Arc<AppContext>, tg_backend: &mut TgBackend) ->
return HandleCliOutcome::Quit;
}
}
// std::thread::sleep(std::time::Duration::from_secs(1));

tracing::info!(
"Sent message {} to chat_name {} ({})",
Expand Down
6 changes: 6 additions & 0 deletions src/tg/tg_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit faa4c43

Please # to comment.