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
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue