2020-05-26 19:45:38 +02:00
|
|
|
//! # Custom emojies helper
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
|
|
|
use crate::data::user::UserID;
|
|
|
|
use crate::data::error::ResultBoxError;
|
|
|
|
use crate::data::custom_emoji::CustomEmoji;
|
|
|
|
use crate::helpers::database;
|
|
|
|
use crate::constants::database_tables_names::EMOJIS_TABLE;
|
|
|
|
|
|
|
|
/// Get the list of emojies of a user
|
2020-06-25 10:08:34 +02:00
|
|
|
pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<CustomEmoji>> {
|
2020-05-26 19:45:38 +02:00
|
|
|
database::QueryInfo::new(EMOJIS_TABLE)
|
2020-06-25 10:08:34 +02:00
|
|
|
.cond_user_id("user_id", user_id)
|
2020-05-26 19:45:38 +02:00
|
|
|
.exec(db_to_custom_emoji)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Turn a database entry into a [CustomEmoji]
|
|
|
|
fn db_to_custom_emoji(row: &database::RowResult) -> ResultBoxError<CustomEmoji> {
|
|
|
|
Ok(CustomEmoji {
|
|
|
|
id: row.get_u64("id")?,
|
2020-06-25 10:08:34 +02:00
|
|
|
user_id: row.get_user_id("user_id")?,
|
2020-05-26 19:45:38 +02:00
|
|
|
shortcut: row.get_str("shortcut")?,
|
|
|
|
path: row.get_str("path")?
|
|
|
|
})
|
|
|
|
}
|