Unified the way we handle the case, where the name hash is invalid

This commit is contained in:
StNicolay 2023-08-07 13:54:52 +03:00
parent 2199889127
commit 4b49d820fc
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
4 changed files with 35 additions and 34 deletions

View File

@ -91,13 +91,10 @@ pub async fn alter(
Some(name) => name,
None => {
try_join!(
ids.alter_message(
&bot,
"Account wasn't found. Choose another one",
menu_markup("get", user_id, &db).await?,
None,
),
bot.answer_callback_query(q.id).send().err_into()
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())
.send(),
bot.answer_callback_query(q.id).send()
)?;
return Ok(());

View File

@ -1,6 +1,6 @@
use crate::{change_state, prelude::*};
use teloxide::types::ParseMode;
use tokio::task::spawn_blocking;
use tokio::{task::spawn_blocking, try_join};
#[inline]
async fn get_master_pass(
@ -47,27 +47,28 @@ pub async fn decrypt(
dialogue: MainDialogue,
hash: super::NameHash,
) -> crate::Result<()> {
let mut msg: MessageIds = q.message.as_ref().unwrap().into();
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
let user_id = q.from.id.0;
let name = match name_from_hash(&db, user_id, &hash).await? {
Some(name) => name,
None => {
msg.alter_message(
&bot,
"Account wan't found. Select another one",
menu_markup("decrypt", user_id, &db).await?,
None,
)
.await?;
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())
.send(),
bot.answer_callback_query(q.id).send()
)?;
return Ok(());
}
};
msg.alter_message(&bot, "Send master password", None, None)
ids.alter_message(&bot, "Send master password", None, None)
.await?;
bot.answer_callback_query(q.id).await?;
change_state!(dialogue, msg, (name), State::GetMasterPass, get_master_pass);
change_state!(dialogue, ids, (name), State::GetMasterPass, get_master_pass);
Ok(())
}

View File

@ -1,3 +1,5 @@
use tokio::try_join;
use crate::{change_state, prelude::*};
#[inline]
@ -34,24 +36,25 @@ pub async fn delete(
dialogue: MainDialogue,
hash: super::NameHash,
) -> crate::Result<()> {
let mut msg: MessageIds = q.message.as_ref().unwrap().into();
let chat_id = q.message.as_ref().unwrap().chat.id;
let user_id = q.from.id.0;
let name = match name_from_hash(&db, user_id, &hash).await? {
Some(name) => name,
None => {
msg.alter_message(
&bot,
"Account wan't found. Select another one",
menu_markup("delete", user_id, &db).await?,
None,
)
.await?;
try_join!(
bot.send_message(chat_id, "Account wasn't found")
.reply_markup(deletion_markup())
.send(),
bot.answer_callback_query(q.id).send()
)?;
return Ok(());
}
};
let previous = bot.send_message(
msg.0,
chat_id,
"Send master password. Once you send correct master password the account is unrecoverable"
).await?;
bot.answer_callback_query(q.id).await?;

View File

@ -1,4 +1,5 @@
use crate::prelude::*;
use futures::try_join;
use teloxide::types::ParseMode;
#[inline]
@ -14,13 +15,12 @@ pub async fn get(
let name = match name_from_hash(&db, user_id, &hash).await? {
Some(name) => name,
None => {
ids.alter_message(
&bot,
"Account wasn't found. Select another one",
menu_markup("get", user_id, &db).await?,
None,
)
.await?;
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())
.send(),
bot.answer_callback_query(q.id).send()
)?;
return Ok(());
}
};