add: post tags
This commit is contained in:
parent
efeb660de6
commit
8c3024cb40
13 changed files with 180 additions and 34 deletions
|
@ -1,5 +1,5 @@
|
|||
CREATE TABLE IF NOT EXISTS requests (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
id BIGINT NOT NULL,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
action_type TEXT NOT NULL,
|
||||
|
|
|
@ -298,6 +298,68 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all posts 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_posts_by_user_tag(
|
||||
&self,
|
||||
id: usize,
|
||||
tag: &str,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
user: &Option<User>,
|
||||
) -> Result<Vec<Post>> {
|
||||
let other_user = self.get_user_by_id(id).await?;
|
||||
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
// check if we should hide nsfw posts
|
||||
let mut hide_nsfw: bool = true;
|
||||
|
||||
if let Some(ua) = user {
|
||||
if ua.id == other_user.id {
|
||||
hide_nsfw = false
|
||||
}
|
||||
}
|
||||
|
||||
if other_user.settings.private_profile {
|
||||
hide_nsfw = false;
|
||||
}
|
||||
|
||||
// ...
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
&format!(
|
||||
"SELECT * FROM posts WHERE owner = $1 AND context::json->>'tags' LIKE $2 {} ORDER BY created DESC LIMIT $3 OFFSET $4",
|
||||
if hide_nsfw {
|
||||
"AND NOT context LIKE '%\"is_nsfw\":true%'"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
),
|
||||
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
|
||||
|
|
|
@ -130,7 +130,9 @@ impl DataManager {
|
|||
.get_request_by_id_linked_asset(id, linked_asset)
|
||||
.await?;
|
||||
|
||||
if !force && user.id != y.owner && !user.permissions.check(FinePermission::MANAGE_REQUESTS)
|
||||
if !force
|
||||
&& (user.id != y.owner && user.id != y.linked_asset)
|
||||
&& !user.permissions.check(FinePermission::MANAGE_REQUESTS)
|
||||
{
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
|
|
@ -174,6 +174,8 @@ pub struct PostContext {
|
|||
pub reactions_enabled: bool,
|
||||
#[serde(default)]
|
||||
pub content_warning: String,
|
||||
#[serde(default)]
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
fn default_comments_enabled() -> bool {
|
||||
|
@ -201,6 +203,7 @@ impl Default for PostContext {
|
|||
answering: 0,
|
||||
reactions_enabled: default_reactions_enabled(),
|
||||
content_warning: String::new(),
|
||||
tags: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue