add: post tags

This commit is contained in:
trisua 2025-05-08 20:08:43 -04:00
parent efeb660de6
commit 8c3024cb40
13 changed files with 180 additions and 34 deletions

View file

@ -140,6 +140,8 @@ pub struct ProfileQuery {
pub page: usize,
#[serde(default)]
pub warning: bool,
#[serde(default)]
pub tag: String,
}
#[derive(Deserialize)]

View file

@ -198,40 +198,66 @@ pub async fn posts_request(
Vec::new()
};
let posts = match data
.0
.get_posts_by_user(other_user.id, 12, props.page, &user)
.await
{
Ok(p) => match data
let posts = if props.tag.is_empty() {
match data
.0
.fill_posts_with_community(
p,
if let Some(ref ua) = user { ua.id } else { 0 },
&ignore_users,
)
.get_posts_by_user(other_user.id, 12, props.page, &user)
.await
{
Ok(p) => p,
Ok(p) => match data
.0
.fill_posts_with_community(
p,
if let Some(ref ua) = user { ua.id } else { 0 },
&ignore_users,
)
.await
{
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
}
} else {
match data
.0
.get_posts_by_user_tag(other_user.id, &props.tag, 12, props.page, &user)
.await
{
Ok(p) => match data
.0
.fill_posts_with_community(
p,
if let Some(ref ua) = user { ua.id } else { 0 },
&ignore_users,
)
.await
{
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
}
};
let pinned = match data.0.get_pinned_posts_by_user(other_user.id).await {
Ok(p) => match data
.0
.fill_posts_with_community(
p,
if let Some(ref ua) = user { ua.id } else { 0 },
&ignore_users,
)
.await
{
Ok(p) => p,
let pinned = if props.tag.is_empty() {
match data.0.get_pinned_posts_by_user(other_user.id).await {
Ok(p) => match data
.0
.fill_posts_with_community(
p,
if let Some(ref ua) = user { ua.id } else { 0 },
&ignore_users,
)
.await
{
Ok(p) => Some(p),
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
}
} else {
None
};
let communities = match data.0.get_memberships_by_owner(other_user.id).await {
@ -282,6 +308,7 @@ pub async fn posts_request(
context.insert("posts", &posts);
context.insert("pinned", &pinned);
context.insert("page", &props.page);
context.insert("tag", &props.tag);
profile_context(
&mut context,
&user,