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

@ -63,11 +63,17 @@
<div class="card flex flex-wrap gap-4 flex-collapse">
<!-- prettier-ignore -->
{% for user in list %}
{% for tu in list %}
{% set reaction = tu[0] %}
{% set user = tu[1] %}
<div
style="display: contents"
title="{% if reaction.is_like %}Like{% else %}Dislike{% endif %}"
>
{{ components::user_plate(user=user, secondary=true) }}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}
</div>
{% endfor %} {{ components::pagination(page=page, items=list|length)
}}
</div>
</div>
</main>

View file

@ -998,7 +998,15 @@ pub async fn likes_request(
// ...
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
let list = match data.0.get_reactions_by_asset(post.id, 12, props.page).await {
let list = match if user.permissions.check(FinePermission::MANAGE_REACTIONS) {
// all reactions
data.0.get_reactions_by_asset(post.id, 12, props.page).await
} else {
// only likes
data.0
.get_likes_reactions_by_asset(post.id, 12, props.page)
.await
} {
Ok(p) => match data.0.fill_reactions(&p, ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),

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,

View file

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
/// All of the items which support reactions.
#[derive(Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum AssetType {
#[serde(alias = "community")]
Community,
@ -14,7 +14,7 @@ pub enum AssetType {
User,
}
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Reaction {
pub id: usize,
pub created: usize,