change create_callback_button to accept Callback instead of CallbackInfo

reason: its more convinient for this function and and ability to create
CallbackInfo with literal
This commit is contained in:
Akulij 2025-05-02 13:23:47 +03:00
parent a3c9cd1bb8
commit 8326e819c7
2 changed files with 8 additions and 12 deletions

View File

@ -15,7 +15,7 @@ use crate::mongodb_storage::MongodbStorage;
use chrono::{DateTime, Utc};
use chrono_tz::Asia;
use db::DbError;
use db::{DbError, Literal};
use envconfig::Envconfig;
use serde::{Deserialize, Serialize};
use teloxide::dispatching::dialogue::serializer::Json;
@ -281,8 +281,7 @@ async fn callback_handler(bot: Bot, mut db: DB, q: CallbackQuery) -> BotResult<(
match callback {
Callback::MoreInfo => {
let keyboard = Some(single_button_markup!(
create_callback_button("go_home", CallbackStore::new(Callback::GoHome), &mut db,)
.await?
create_callback_button("go_home", Callback::GoHome, &mut db).await?
));
replace_message(
@ -788,15 +787,10 @@ async fn replace_message(
async fn make_start_buttons(db: &mut DB) -> BotResult<InlineKeyboardMarkup> {
let mut buttons: Vec<Vec<InlineKeyboardButton>> = Vec::new();
buttons.push(vec![
create_callback_button(
"show_projects",
CallbackStore::new(Callback::ProjectPage { id: 1 }),
db,
)
.await?,
create_callback_button("show_projects", Callback::ProjectPage { id: 1 }, db).await?,
]);
buttons.push(vec![
create_callback_button("more_info", CallbackStore::new(Callback::MoreInfo), db).await?,
create_callback_button("more_info", Callback::MoreInfo, db).await?,
]);
Ok(InlineKeyboardMarkup::new(buttons))

View File

@ -30,7 +30,7 @@ macro_rules! stacked_buttons_markup {
pub async fn create_callback_button<C, D>(
literal: &str,
ci: CallbackInfo<C>,
callback: C,
db: &mut D,
) -> BotResult<InlineKeyboardButton>
where
@ -41,7 +41,9 @@ where
.get_literal_value(literal)
.await?
.unwrap_or("Please, set content of this message".into());
let ci = ci.store(db).await?;
let ci = CallbackInfo::new_with_literal(callback, literal.to_string())
.store(db)
.await?;
Ok(InlineKeyboardButton::new(
text,