add: custom emojis

fix: don't show reposts of posts from blocked users
fix: don't show questions when they're from users you've blocked
This commit is contained in:
trisua 2025-05-10 21:58:02 -04:00
parent 9f187039e6
commit 275dd0a1eb
25 changed files with 697 additions and 61 deletions

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use crate::model::{
@ -55,6 +57,29 @@ impl DataManager {
Ok(res.unwrap())
}
/// Get all emojis by their community for the communities the given user is in.
pub async fn get_user_emojis(
&self,
id: usize,
) -> Result<HashMap<usize, (String, Vec<CustomEmoji>)>> {
let memberships = self.get_memberships_by_owner(id).await?;
let mut out = HashMap::new();
for membership in memberships {
let community = self.get_community_by_id(membership.community).await?;
out.insert(
community.id,
(
community.title.clone(),
self.get_emojis_by_community(community.id).await?,
),
);
}
Ok(out)
}
/// Get an emoji by community and name.
///
/// # Arguments
@ -134,8 +159,8 @@ impl DataManager {
"INSERT INTO emojis VALUES ($1, $2, $3, $4, $5, $6, $7)",
params![
&(data.id as i64),
&(data.owner as i64),
&(data.created as i64),
&(data.owner as i64),
&(data.community as i64),
&(data.upload_id as i64),
&data.name,
@ -176,7 +201,7 @@ impl DataManager {
return Err(Error::DatabaseError(e.to_string()));
}
// delete uploads
// delete upload
self.delete_upload(emoji.upload_id).await?;
// ...
@ -184,5 +209,5 @@ impl DataManager {
Ok(())
}
auto_method!(update_emoji_name(&str)@get_emoji_by_id:MANAGE_EMOJIS -> "UPDATE emojis SET title = $1 WHERE id = $2" --cache-key-tmpl="atto.emoji:{}");
auto_method!(update_emoji_name(&str)@get_emoji_by_id:MANAGE_EMOJIS -> "UPDATE emojis SET name = $1 WHERE id = $2" --cache-key-tmpl="atto.emoji:{}");
}