Added the check that accounts exist for /get_account and /delete

This commit is contained in:
StNicolay 2023-08-08 15:09:13 +03:00
parent 4b49d820fc
commit 2976d7f9f3
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 30 additions and 4 deletions

View File

@ -1,12 +1,25 @@
use crate::prelude::*;
use tokio::task::spawn_blocking;
#[inline]
pub async fn delete(bot: Throttle<Bot>, 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<String> = 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(())
}

View File

@ -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<String> = 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(())
}