mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-22 01:15:16 +00:00
Can delete a custom emoji
This commit is contained in:
@ -16,6 +16,13 @@ pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<CustomEmoji>> {
|
||||
.exec(db_to_custom_emoji)
|
||||
}
|
||||
|
||||
/// Get information about a single emoji
|
||||
pub fn get_single(emoji_id: u64) -> ResultBoxError<CustomEmoji> {
|
||||
database::QueryInfo::new(EMOJIS_TABLE)
|
||||
.cond_u64("id", emoji_id)
|
||||
.query_row(db_to_custom_emoji)
|
||||
}
|
||||
|
||||
/// Check if a given user already as an emoji shortcut or not
|
||||
pub fn has_user_similar_shortcut(user_id: &UserID, shortcut: &str) -> ResultBoxError<bool> {
|
||||
database::QueryInfo::new(EMOJIS_TABLE)
|
||||
@ -34,6 +41,19 @@ pub fn insert(emoji: &NewCustomEmoji) -> ResultBoxError<u64> {
|
||||
.insert_expect_result()
|
||||
}
|
||||
|
||||
/// Delete a custom emoji
|
||||
pub fn delete(c: &CustomEmoji) -> ResultBoxError {
|
||||
let path = c.sys_path();
|
||||
|
||||
if path.exists() {
|
||||
std::fs::remove_file(path)?;
|
||||
}
|
||||
|
||||
database::DeleteQuery::new(EMOJIS_TABLE)
|
||||
.cond_u64("id", c.id)
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Turn a database entry into a [CustomEmoji]
|
||||
fn db_to_custom_emoji(row: &database::RowResult) -> ResultBoxError<CustomEmoji> {
|
||||
Ok(CustomEmoji {
|
||||
|
Reference in New Issue
Block a user