diff --git a/crates/app/src/public/html/post/likes.html b/crates/app/src/public/html/post/likes.html
index 0314eed..18ff3e1 100644
--- a/crates/app/src/public/html/post/likes.html
+++ b/crates/app/src/public/html/post/likes.html
@@ -63,11 +63,17 @@
- {% for user in list %}
+ {% for tu in list %}
+ {% set reaction = tu[0] %}
+ {% set user = tu[1] %}
+
{{ components::user_plate(user=user, secondary=true) }}
- {% endfor %}
-
- {{ components::pagination(page=page, items=list|length) }}
+
+ {% endfor %} {{ components::pagination(page=page, items=list|length)
+ }}
diff --git a/crates/app/src/routes/pages/communities.rs b/crates/app/src/routes/pages/communities.rs
index 17216ae..c1b2c6d 100644
--- a/crates/app/src/routes/pages/communities.rs
+++ b/crates/app/src/routes/pages/communities.rs
@@ -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)),
diff --git a/crates/core/src/database/reactions.rs b/crates/core/src/database/reactions.rs
index 99fbcca..bacf042 100644
--- a/crates/core/src/database/reactions.rs
+++ b/crates/core/src/database/reactions.rs
@@ -37,7 +37,7 @@ impl DataManager {
&self,
reactions: &Vec,
ignore_users: Vec,
- ) -> Result> {
+ ) -> Result> {
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> {
+ 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,
diff --git a/crates/core/src/model/reactions.rs b/crates/core/src/model/reactions.rs
index 239f8b2..9987e03 100644
--- a/crates/core/src/model/reactions.rs
+++ b/crates/core/src/model/reactions.rs
@@ -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,