fix: don't show dislikes to regular users

This commit is contained in:
trisua 2025-05-19 18:52:47 -04:00
parent 0ae283ad8e
commit a4d7f44aa3
4 changed files with 53 additions and 10 deletions

View file

@ -37,7 +37,7 @@ impl DataManager {
&self,
reactions: &Vec<Reaction>,
ignore_users: Vec<usize>,
) -> Result<Vec<User>> {
) -> Result<Vec<(Reaction, User)>> {
let mut out = Vec::new();
for reaction in reactions {
@ -45,13 +45,16 @@ impl DataManager {
continue;
}
out.push(self.get_user_by_id(reaction.owner.to_owned()).await?);
out.push((
reaction.to_owned(),
self.get_user_by_id(reaction.owner.to_owned()).await?,
));
}
Ok(out)
}
/// Get a reaction by `owner` and `asset`.
/// Get all reactions by their `asset`.
pub async fn get_reactions_by_asset(
&self,
asset: usize,
@ -77,6 +80,32 @@ impl DataManager {
Ok(res.unwrap())
}
/// Get all reactions (likes only) by their `asset`.
pub async fn get_likes_reactions_by_asset(
&self,
asset: usize,
batch: usize,
page: usize,
) -> Result<Vec<Reaction>> {
let conn = match self.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = query_rows!(
&conn,
"SELECT * FROM reactions WHERE asset = $1 AND is_like = 1 ORDER BY created DESC LIMIT $2 OFFSET $3",
&[&(asset as i64), &(batch as i64), &((page * batch) as i64)],
|x| { Self::get_reaction_from_row(x) }
);
if res.is_err() {
return Err(Error::GeneralNotFound("reaction".to_string()));
}
Ok(res.unwrap())
}
/// Get a reaction by `owner` and `asset`.
pub async fn get_reaction_by_owner_asset(
&self,