add: dedicated responses tab for profiles
This commit is contained in:
parent
9ba6320d46
commit
07a23f505b
24 changed files with 332 additions and 55 deletions
|
@ -758,6 +758,37 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all posts (that are answering a question) from the given user (from most recent).
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - the ID of the user the requested posts belong to
|
||||
/// * `batch` - the limit of posts in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_responses_by_user(
|
||||
&self,
|
||||
id: usize,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<Post>> {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE owner = $1 AND replying_to = 0 AND NOT (context::json->>'is_profile_pinned')::boolean AND is_deleted = 0 AND NOT context::jsonb->>'answering' = '0' ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("post".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Calculate the GPA (great post average) of a given user.
|
||||
///
|
||||
/// To be considered a "great post", a post must have a score ((likes - dislikes) / (likes + dislikes))
|
||||
|
@ -1066,6 +1097,45 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all posts (that are answering a question) from the given user
|
||||
/// with the given tag (from most recent).
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - the ID of the user the requested posts belong to
|
||||
/// * `tag` - the tag to filter by
|
||||
/// * `batch` - the limit of posts in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_responses_by_user_tag(
|
||||
&self,
|
||||
id: usize,
|
||||
tag: &str,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<Post>> {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE owner = $1 AND context::json->>'tags' LIKE $2 AND is_deleted = 0 AND NOT context::jsonb->>'answering' = '0' ORDER BY created DESC LIMIT $3 OFFSET $4",
|
||||
params![
|
||||
&(id as i64),
|
||||
&format!("%\"{tag}\"%"),
|
||||
&(batch as i64),
|
||||
&((page * batch) as i64)
|
||||
],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("post".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all posts from the given community (from most recent).
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -1661,8 +1731,12 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// award achievement
|
||||
self.add_achievement(&mut owner, AchievementName::CreatePostWithTitle.into())
|
||||
.await?;
|
||||
self.add_achievement(
|
||||
&mut owner,
|
||||
AchievementName::CreatePostWithTitle.into(),
|
||||
true,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1803,7 +1877,7 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// award achievement
|
||||
self.add_achievement(&mut owner, AchievementName::CreateRepost.into())
|
||||
self.add_achievement(&mut owner, AchievementName::CreateRepost.into(), true)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue