Updated delete callback handler to alter a message if /delete command was used
This commit is contained in:
parent
6691ab12de
commit
06492bf31e
@ -1,3 +1,4 @@
|
||||
use futures::TryFutureExt;
|
||||
use tokio::try_join;
|
||||
|
||||
use crate::{change_state, prelude::*};
|
||||
@ -34,16 +35,16 @@ pub async fn delete(
|
||||
q: CallbackQuery,
|
||||
db: DatabaseConnection,
|
||||
dialogue: MainDialogue,
|
||||
hash: super::NameHash,
|
||||
(hash, is_command): (super::NameHash, bool),
|
||||
) -> crate::Result<()> {
|
||||
let chat_id = q.message.as_ref().unwrap().chat.id;
|
||||
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 => {
|
||||
try_join!(
|
||||
bot.send_message(chat_id, "Account wasn't found")
|
||||
bot.send_message(ids.0, "Account wasn't found")
|
||||
.reply_markup(deletion_markup())
|
||||
.send(),
|
||||
bot.answer_callback_query(q.id).send()
|
||||
@ -53,19 +54,23 @@ pub async fn delete(
|
||||
}
|
||||
};
|
||||
|
||||
let previous = bot.send_message(
|
||||
chat_id,
|
||||
"Send master password. Once you send correct master password the account is unrecoverable"
|
||||
).await?;
|
||||
bot.answer_callback_query(q.id).await?;
|
||||
let response = async {
|
||||
const TEXT: &str =
|
||||
"Send master password. Once you send the master password the account is unrecoverable";
|
||||
|
||||
change_state!(
|
||||
dialogue,
|
||||
&previous,
|
||||
(name),
|
||||
State::GetMasterPass,
|
||||
get_master_pass
|
||||
);
|
||||
if is_command {
|
||||
ids.alter_message(&bot, TEXT, None, None).await?
|
||||
} else {
|
||||
let msg = bot.send_message(ids.0, TEXT).await?;
|
||||
ids = MessageIds::from(&msg)
|
||||
};
|
||||
|
||||
Ok::<_, crate::Error>(())
|
||||
};
|
||||
|
||||
try_join!(response, bot.answer_callback_query(q.id).send().err_into())?;
|
||||
|
||||
change_state!(dialogue, ids, (name), State::GetMasterPass, get_master_pass);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ pub enum CallbackCommand {
|
||||
Decrypt(NameHash),
|
||||
Hide(NameHash),
|
||||
Alter(NameHash, AlterableField),
|
||||
DeleteAccount(NameHash),
|
||||
DeleteAccount { name: NameHash, is_command: bool },
|
||||
}
|
||||
|
||||
impl CallbackCommand {
|
||||
@ -64,7 +64,14 @@ impl FromStr for CallbackCommand {
|
||||
"an" => Ok(Alter(name_hash, Name)),
|
||||
"al" => Ok(Alter(name_hash, Login)),
|
||||
"ap" => Ok(Alter(name_hash, Pass)),
|
||||
"delete" => Ok(DeleteAccount(name_hash)),
|
||||
"delete0" => Ok(DeleteAccount {
|
||||
name: name_hash,
|
||||
is_command: false,
|
||||
}),
|
||||
"delete1" => Ok(DeleteAccount {
|
||||
name: name_hash,
|
||||
is_command: true,
|
||||
}),
|
||||
_ => Err(InvalidCommand::InvalidParams),
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub async fn delete(bot: Throttle<Bot>, msg: Message, db: DatabaseConnection) ->
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let markup = spawn_blocking(|| menu_markup_sync("delete", names)).await?;
|
||||
let markup = spawn_blocking(|| menu_markup_sync("delete1", names)).await?;
|
||||
bot.send_message(msg.chat.id, "Choose the account to delete")
|
||||
.reply_markup(markup)
|
||||
.await?;
|
||||
|
@ -62,7 +62,9 @@ fn get_dispatcher(
|
||||
.branch(case![CallbackCommand::DeleteMessage].endpoint(callbacks::delete_message))
|
||||
.branch(case![CallbackCommand::Get(hash)].endpoint(callbacks::get))
|
||||
.branch(case![CallbackCommand::Decrypt(hash)].endpoint(callbacks::decrypt))
|
||||
.branch(case![CallbackCommand::DeleteAccount(hash)].endpoint(callbacks::delete))
|
||||
.branch(
|
||||
case![CallbackCommand::DeleteAccount { name, is_command }].endpoint(callbacks::delete),
|
||||
)
|
||||
.branch(case![CallbackCommand::Alter(hash, field)].endpoint(callbacks::alter));
|
||||
|
||||
let handler = dptree::entry()
|
||||
|
@ -67,7 +67,7 @@ pub fn account_markup(name: &str, is_encrypted: bool) -> InlineKeyboardMarkup {
|
||||
("Alter login", "al"),
|
||||
("Alter password", "ap"),
|
||||
encryption_button,
|
||||
("Delete account", "delete"),
|
||||
("Delete account", "delete0"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(text, command)| make_button(text, command, hash))
|
||||
|
Loading…
Reference in New Issue
Block a user