diff --git a/src/commands/delete.rs b/src/commands/delete.rs index 49cf0a2..77f70be 100644 --- a/src/commands/delete.rs +++ b/src/commands/delete.rs @@ -1,12 +1,25 @@ use crate::prelude::*; +use tokio::task::spawn_blocking; #[inline] pub async fn delete(bot: Throttle, msg: Message, db: DatabaseConnection) -> crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - bot.send_message(msg.chat.id, "Choose the account to delete") - .reply_markup(menu_markup("delete", user_id, &db).await?) + let names: Vec = Account::get_names(user_id, &db) + .await? + .try_collect() .await?; + if names.is_empty() { + bot.send_message(msg.chat.id, "You don't have any accounts") + .reply_markup(deletion_markup()) + .await?; + return Ok(()); + } + + let markup = spawn_blocking(|| menu_markup_sync("delete", names)).await?; + bot.send_message(msg.chat.id, "Choose the account to delete") + .reply_markup(markup) + .await?; Ok(()) } diff --git a/src/commands/get_account.rs b/src/commands/get_account.rs index 1071d94..15d4d59 100644 --- a/src/commands/get_account.rs +++ b/src/commands/get_account.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use tokio::task::spawn_blocking; #[inline] pub async fn get_account( @@ -8,9 +9,21 @@ pub async fn get_account( ) -> crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - bot.send_message(msg.chat.id, "Choose the account to get") - .reply_markup(menu_markup("decrypt", user_id, &db).await?) + let names: Vec = Account::get_names(user_id, &db) + .await? + .try_collect() .await?; + if names.is_empty() { + bot.send_message(msg.chat.id, "You don't have any accounts") + .reply_markup(deletion_markup()) + .await?; + return Ok(()); + } + + let markup = spawn_blocking(|| menu_markup_sync("decrypt", names)).await?; + bot.send_message(msg.chat.id, "Choose the account to get") + .reply_markup(markup) + .await?; Ok(()) }