Changed get.rs and get_menu.rs to use MessageIds::alter_message func
This commit is contained in:
		@@ -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?;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
use crate::prelude::*;
 | 
			
		||||
use tokio::task::spawn_blocking;
 | 
			
		||||
 | 
			
		||||
pub async fn get_menu(
 | 
			
		||||
    bot: Throttle<Bot>,
 | 
			
		||||
@@ -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<String> = 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(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user