Sepparated the code out into 3 more library crates: cryptography, entity and pass_manager
This commit is contained in:
31
src/markups.rs
Normal file
31
src/markups.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use entity::prelude::Account;
|
||||
use futures::TryStreamExt;
|
||||
use sea_orm::prelude::*;
|
||||
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, KeyboardMarkup};
|
||||
|
||||
/// Creates a markup of all user's account names
|
||||
#[inline]
|
||||
pub async fn account_markup(
|
||||
user_id: u64,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<KeyboardMarkup> {
|
||||
let account_names: Vec<Vec<KeyboardButton>> = Account::get_names(user_id, db, true)
|
||||
.await?
|
||||
.map_ok(KeyboardButton::new)
|
||||
.try_chunks(3)
|
||||
.map_err(|err| err.1)
|
||||
.try_collect()
|
||||
.await?;
|
||||
let markup = KeyboardMarkup::new(account_names)
|
||||
.resize_keyboard(true)
|
||||
.one_time_keyboard(true);
|
||||
Ok(markup)
|
||||
}
|
||||
|
||||
/// Creates a markup with a "Delete message" button.
|
||||
/// This markup should be added for all messages that won't be deleted afterwards
|
||||
#[inline]
|
||||
pub fn deletion_markup() -> InlineKeyboardMarkup {
|
||||
let button = InlineKeyboardButton::callback("Delete message", "delete_message");
|
||||
InlineKeyboardMarkup::new([[button]])
|
||||
}
|
Reference in New Issue
Block a user