fix: don't show dislikes to regular users
This commit is contained in:
parent
0ae283ad8e
commit
a4d7f44aa3
4 changed files with 53 additions and 10 deletions
|
@ -63,11 +63,17 @@
|
||||||
|
|
||||||
<div class="card flex flex-wrap gap-4 flex-collapse">
|
<div class="card flex flex-wrap gap-4 flex-collapse">
|
||||||
<!-- prettier-ignore -->
|
<!-- 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) }}
|
{{ components::user_plate(user=user, secondary=true) }}
|
||||||
{% endfor %}
|
</div>
|
||||||
|
{% endfor %} {{ components::pagination(page=page, items=list|length)
|
||||||
{{ components::pagination(page=page, items=list|length) }}
|
}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
@ -998,7 +998,15 @@ pub async fn likes_request(
|
||||||
// ...
|
// ...
|
||||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
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) => match data.0.fill_reactions(&p, ignore_users).await {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl DataManager {
|
||||||
&self,
|
&self,
|
||||||
reactions: &Vec<Reaction>,
|
reactions: &Vec<Reaction>,
|
||||||
ignore_users: Vec<usize>,
|
ignore_users: Vec<usize>,
|
||||||
) -> Result<Vec<User>> {
|
) -> Result<Vec<(Reaction, User)>> {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
|
|
||||||
for reaction in reactions {
|
for reaction in reactions {
|
||||||
|
@ -45,13 +45,16 @@ impl DataManager {
|
||||||
continue;
|
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)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reaction by `owner` and `asset`.
|
/// Get all reactions by their `asset`.
|
||||||
pub async fn get_reactions_by_asset(
|
pub async fn get_reactions_by_asset(
|
||||||
&self,
|
&self,
|
||||||
asset: usize,
|
asset: usize,
|
||||||
|
@ -77,6 +80,32 @@ impl DataManager {
|
||||||
Ok(res.unwrap())
|
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`.
|
/// Get a reaction by `owner` and `asset`.
|
||||||
pub async fn get_reaction_by_owner_asset(
|
pub async fn get_reaction_by_owner_asset(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||||
|
|
||||||
/// All of the items which support reactions.
|
/// All of the items which support reactions.
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub enum AssetType {
|
pub enum AssetType {
|
||||||
#[serde(alias = "community")]
|
#[serde(alias = "community")]
|
||||||
Community,
|
Community,
|
||||||
|
@ -14,7 +14,7 @@ pub enum AssetType {
|
||||||
User,
|
User,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct Reaction {
|
pub struct Reaction {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub created: usize,
|
pub created: usize,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue