Now forming MessageIds only from &Message to reduce the amount of moving this large type
This commit is contained in:
parent
e25460a3d8
commit
1225adefc2
@ -43,7 +43,7 @@ async fn get_password(
|
||||
move |bot, msg, db, dialogue, master_pass| {
|
||||
get_master_pass(bot, msg, db, dialogue, account, master_pass)
|
||||
},
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -64,7 +64,7 @@ async fn get_login(
|
||||
move |bot, msg, db, dialogue, password| {
|
||||
get_password(bot, msg, db, dialogue, name, login, password)
|
||||
},
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -82,7 +82,7 @@ async fn get_account_name(
|
||||
dialogue
|
||||
.update(State::GetLogin(Handler::new(
|
||||
move |bot, msg, db, dialogue, login| get_login(bot, msg, db, dialogue, name, login),
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -96,7 +96,7 @@ pub async fn add_account(
|
||||
) -> crate::Result<()> {
|
||||
let previous = bot.send_message(msg.chat.id, "Send account name").await?;
|
||||
dialogue
|
||||
.update(State::GetNewName(Handler::new(get_account_name, previous)))
|
||||
.update(State::GetNewName(Handler::new(get_account_name, &previous)))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ async fn get_account_name(
|
||||
dialogue
|
||||
.update(State::GetMasterPass(Handler::new(
|
||||
move |bot, msg, db, dialogue, _| get_master_pass(bot, msg, db, dialogue, name),
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -60,7 +60,7 @@ pub async fn delete(
|
||||
dialogue
|
||||
.update(State::GetExistingName(Handler::new(
|
||||
get_account_name,
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -40,7 +40,7 @@ pub async fn delete_all(
|
||||
dialogue
|
||||
.update(State::GetMasterPass(Handler::new(
|
||||
get_master_pass,
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -61,7 +61,7 @@ pub async fn export(bot: Throttle<Bot>, msg: Message, dialogue: MainDialogue) ->
|
||||
dialogue
|
||||
.update(State::GetMasterPass(Handler::new(
|
||||
get_master_pass,
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -47,7 +47,7 @@ async fn get_account_name(
|
||||
move |bot, msg, db, dialogue, master_pass| {
|
||||
get_master_pass(bot, msg, db, dialogue, name, master_pass)
|
||||
},
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -75,7 +75,7 @@ pub async fn get_account(
|
||||
dialogue
|
||||
.update(State::GetExistingName(Handler::new(
|
||||
get_account_name,
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -79,7 +79,7 @@ async fn get_document(
|
||||
move |bot, msg, db, dialogue, master_pass| {
|
||||
get_master_pass(bot, msg, db, dialogue, master_pass, user)
|
||||
},
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -94,7 +94,7 @@ pub async fn import(bot: Throttle<Bot>, msg: Message, dialogue: MainDialogue) ->
|
||||
)
|
||||
.await?;
|
||||
dialogue
|
||||
.update(State::GetUser(Handler::new(get_document, previous)))
|
||||
.update(State::GetUser(Handler::new(get_document, &previous)))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ pub async fn set_master_pass(
|
||||
dialogue
|
||||
.update(State::GetNewMasterPass(Handler::new(
|
||||
get_master_pass,
|
||||
previous,
|
||||
&previous,
|
||||
)))
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -4,7 +4,7 @@ pub(crate) use crate::{
|
||||
markups::*,
|
||||
models::*,
|
||||
state::State,
|
||||
state::{Handler, MainDialogue, PackagedHandler},
|
||||
state::{Handler, MainDialogue, MessageIds, PackagedHandler},
|
||||
utils::*,
|
||||
};
|
||||
pub(crate) use cryptography::prelude::*;
|
||||
|
@ -32,7 +32,7 @@ where
|
||||
Some(text) => text.trim(),
|
||||
None => {
|
||||
let msg = bot.send_message(msg.chat.id, no_text_message).await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@ -46,7 +46,7 @@ where
|
||||
}
|
||||
|
||||
if let Some(failure_message) = check(&bot, &msg, &db, text).await? {
|
||||
handler.previous = failure_message.into();
|
||||
handler.previous = MessageIds::from(&failure_message);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ pub async fn get_existing_name(
|
||||
)
|
||||
.reply_markup(account_markup(user_id, &db).await?)
|
||||
.await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@ -61,7 +61,7 @@ pub async fn get_existing_name(
|
||||
}
|
||||
|
||||
if let Some(failure_message) = check_name(&bot, &msg, &db, text, user_id).await? {
|
||||
handler.previous = failure_message.into();
|
||||
handler.previous = MessageIds::from(&failure_message);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ pub async fn get_user(
|
||||
let msg = bot
|
||||
.send_message(msg.chat.id, "You didn't send a file. Try again")
|
||||
.await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@ -151,7 +151,7 @@ pub async fn get_user(
|
||||
"Invalid file name. You need to send a json file. Try again",
|
||||
)
|
||||
.await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -170,14 +170,14 @@ pub async fn get_user(
|
||||
Ok(Ok(user)) => user,
|
||||
Ok(Err(error_text)) => {
|
||||
let msg = bot.send_message(msg.chat.id, error_text).await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
Err(_) => {
|
||||
let msg = bot
|
||||
.send_message(msg.chat.id, "Error parsing the json file. Try again")
|
||||
.await?;
|
||||
handler.previous = msg.into();
|
||||
handler.previous = MessageIds::from(&msg);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
use futures::future::BoxFuture;
|
||||
use std::{borrow::Borrow, future::Future, sync::Arc};
|
||||
use std::{future::Future, sync::Arc};
|
||||
use teloxide::types::MessageId;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@ -14,10 +14,9 @@ impl MessageIds {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Borrow<Message>> From<T> for MessageIds {
|
||||
impl From<&Message> for MessageIds {
|
||||
#[inline]
|
||||
fn from(value: T) -> Self {
|
||||
let value: &Message = value.borrow();
|
||||
fn from(value: &Message) -> Self {
|
||||
Self(value.chat.id, value.id)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub use get_new_master_pass::get_new_master_pass;
|
||||
pub use get_new_name::get_new_name;
|
||||
pub use get_password::get_password;
|
||||
pub use get_user::get_user;
|
||||
pub use handler::{Handler, PackagedHandler};
|
||||
pub use handler::{Handler, MessageIds, PackagedHandler};
|
||||
|
||||
use crate::prelude::*;
|
||||
use teloxide::dispatching::dialogue::InMemStorage;
|
||||
|
Loading…
Reference in New Issue
Block a user