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, Some(name) => name,
None => { None => {
try_join!( try_join!(
ids.alter_message( bot.send_message(ids.0, "Account wasn't found")
&bot, .reply_markup(deletion_markup())
"Account wasn't found. Choose another one", .send(),
menu_markup("get", user_id, &db).await?, bot.answer_callback_query(q.id).send()
None,
),
bot.answer_callback_query(q.id).send().err_into()
)?; )?;
return Ok(()); return Ok(());

View File

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

View File

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

View File

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