diff --git a/src/callbacks/get.rs b/src/callbacks/get.rs index 296c2cc..0e8331f 100644 --- a/src/callbacks/get.rs +++ b/src/callbacks/get.rs @@ -8,24 +8,24 @@ pub async fn get( hash: super::NameHash, ) -> crate::Result<()> { let user_id = q.from.id.0; - let msg = q.message.as_ref().unwrap(); + let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let name = match name_from_hash(&db, user_id, &hash).await? { Some(name) => name, None => { - bot.edit_message_text( - msg.chat.id, - msg.id, - "Account wan't found. Select another one", + ids.alter_message( + &bot, + "Account wasn't found. Select another one", + menu_markup("get", user_id, &db).await?, + None, ) - .reply_markup(menu_markup("get", user_id, &db).await?) .await?; return Ok(()); } }; let text = format!("Name:\n`{name}`\nLogin:\n\\*\\*\\*\nPassword:\n\\*\\*\\*"); - bot.send_message(msg.chat.id, text) + bot.send_message(ids.0, text) .reply_markup(account_markup(&name, true)) .parse_mode(ParseMode::MarkdownV2) .await?; diff --git a/src/callbacks/get_menu.rs b/src/callbacks/get_menu.rs index 77d2ac1..da51c75 100644 --- a/src/callbacks/get_menu.rs +++ b/src/callbacks/get_menu.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use tokio::task::spawn_blocking; pub async fn get_menu( bot: Throttle, @@ -7,23 +6,16 @@ pub async fn get_menu( db: DatabaseConnection, ) -> crate::Result<()> { let user_id = q.from.id.0; - let msg = q.message.as_ref().unwrap(); + let mut ids: MessageIds = q.message.as_ref().unwrap().into(); - let names: Vec = Account::get_names(user_id, &db) - .await? - .try_collect() - .await?; - - if names.is_empty() { - bot.edit_message_text(msg.chat.id, msg.id, "You don't have any accounts") - .reply_markup(deletion_markup()) + let markup = menu_markup("get", user_id, &db).await?; + if markup.inline_keyboard.is_empty() { + ids.alter_message(&bot, "You don't have any accounts", deletion_markup(), None) .await?; return Ok(()); } - let markup = spawn_blocking(|| menu_markup_sync("get", names)).await?; - bot.edit_message_text(msg.chat.id, msg.id, "Choose your account") - .reply_markup(markup) + ids.alter_message(&bot, "Choose your account", markup, None) .await?; Ok(()) }