Changed get.rs and get_menu.rs to use MessageIds::alter_message func

This commit is contained in:
StNicolay 2023-07-29 15:39:32 +03:00
parent af95e16622
commit b456896894
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 12 additions and 20 deletions

View File

@ -8,24 +8,24 @@ pub async fn get(
hash: super::NameHash, hash: super::NameHash,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = q.from.id.0; 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? { let name = match name_from_hash(&db, user_id, &hash).await? {
Some(name) => name, Some(name) => name,
None => { None => {
bot.edit_message_text( ids.alter_message(
msg.chat.id, &bot,
msg.id, "Account wasn't found. Select another one",
"Account wan't found. Select another one", menu_markup("get", user_id, &db).await?,
None,
) )
.reply_markup(menu_markup("get", user_id, &db).await?)
.await?; .await?;
return Ok(()); return Ok(());
} }
}; };
let text = format!("Name:\n`{name}`\nLogin:\n\\*\\*\\*\nPassword:\n\\*\\*\\*"); 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)) .reply_markup(account_markup(&name, true))
.parse_mode(ParseMode::MarkdownV2) .parse_mode(ParseMode::MarkdownV2)
.await?; .await?;

View File

@ -1,5 +1,4 @@
use crate::prelude::*; use crate::prelude::*;
use tokio::task::spawn_blocking;
pub async fn get_menu( pub async fn get_menu(
bot: Throttle<Bot>, bot: Throttle<Bot>,
@ -7,23 +6,16 @@ pub async fn get_menu(
db: DatabaseConnection, db: DatabaseConnection,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = q.from.id.0; 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<String> = Account::get_names(user_id, &db) let markup = menu_markup("get", user_id, &db).await?;
.await? if markup.inline_keyboard.is_empty() {
.try_collect() ids.alter_message(&bot, "You don't have any accounts", deletion_markup(), None)
.await?;
if names.is_empty() {
bot.edit_message_text(msg.chat.id, msg.id, "You don't have any accounts")
.reply_markup(deletion_markup())
.await?; .await?;
return Ok(()); return Ok(());
} }
let markup = spawn_blocking(|| menu_markup_sync("get", names)).await?; ids.alter_message(&bot, "Choose your account", markup, None)
bot.edit_message_text(msg.chat.id, msg.id, "Choose your account")
.reply_markup(markup)
.await?; .await?;
Ok(()) Ok(())
} }