add: reposts/quotes pages

add: repost notification
This commit is contained in:
trisua 2025-04-23 16:46:13 -04:00
parent 41250ef7ed
commit 276f25a496
17 changed files with 601 additions and 50 deletions

View file

@ -1,4 +1,4 @@
use super::{render_error, PaginatedQuery, SearchedQuery};
use super::{render_error, PaginatedQuery, RepostsQuery, SearchedQuery};
use crate::{assets::initial_context, get_lang, get_user_from_token, sanitize::clean_context, State};
use axum::{
Extension,
@ -327,12 +327,18 @@ pub async fn feed_request(
let (can_read, _) = check_permissions!(community, jar, data, user);
// ...
let ignore_users = if let Some(ref ua) = user {
data.0.get_userblocks_receivers(ua.id).await
} else {
Vec::new()
};
let feed = match data
.0
.get_posts_by_community(community.id, 12, props.page)
.await
{
Ok(p) => match data.0.fill_posts(p).await {
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
@ -340,7 +346,7 @@ pub async fn feed_request(
};
let pinned = match data.0.get_pinned_posts_by_community(community.id).await {
Ok(p) => match data.0.fill_posts(p).await {
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
@ -423,12 +429,18 @@ pub async fn questions_request(
let (can_read, _) = check_permissions!(community, jar, data, user);
// ...
let ignore_users = if let Some(ref ua) = user {
data.0.get_userblocks_receivers(ua.id).await
} else {
Vec::new()
};
let feed = match data
.0
.get_questions_by_community(community.id, 12, props.page)
.await
{
Ok(p) => match data.0.fill_questions(p).await {
Ok(p) => match data.0.fill_questions(p, &ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
@ -570,8 +582,14 @@ pub async fn post_request(
}
// ...
let ignore_users = if let Some(ref ua) = user {
data.0.get_userblocks_receivers(ua.id).await
} else {
Vec::new()
};
let feed = match data.0.get_post_comments(post.id, 12, props.page).await {
Ok(p) => match data.0.fill_posts(p).await {
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},
@ -628,9 +646,132 @@ pub async fn post_request(
can_manage_questions,
);
// return
Ok(Html(data.1.render("post/post.html", &context).unwrap()))
}
/// `/post/{id}/reposts`
pub async fn reposts_request(
jar: CookieJar,
Path(id): Path<usize>,
Query(props): Query<RepostsQuery>,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = data.read().await;
let user = get_user_from_token!(jar, data.0);
let post = match data.0.get_post_by_id(id).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
let community = match data.0.get_community_by_id(post.community).await {
Ok(c) => c,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
// check repost
let reposting = data.0.get_post_reposting(&post).await;
// check question
let question = match data.0.get_post_question(&post).await {
Ok(q) => q,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
// check permissions
let (can_read, _) = check_permissions!(community, jar, data, user);
if !can_read {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
// ...
let ignore_users = if let Some(ref ua) = user {
data.0.get_userblocks_receivers(ua.id).await
} else {
Vec::new()
};
let list = if props.quotes {
match data
.0
.get_quoting_posts_by_quoting(post.id, 12, props.page)
.await
{
Ok(p) => match data.0.fill_posts(p, &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)),
}
} else {
match data.0.get_reposts_by_quoting(post.id, 12, props.page).await {
Ok(p) => match data.0.fill_posts(p, &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)),
}
};
// init context
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &user).await;
let (
is_owner,
is_joined,
is_pending,
can_post,
can_manage_posts,
can_manage_community,
can_manage_roles,
can_manage_questions,
) = community_context_bools!(data, user, community);
context.insert("post", &post);
context.insert("reposting", &reposting);
context.insert("question", &question);
context.insert("list", &list);
context.insert("page", &props.page);
context.insert(
"owner",
&data
.0
.get_user_by_id(post.owner)
.await
.unwrap_or(User::deleted()),
);
community_context(
&mut context,
&community,
is_owner,
is_joined,
is_pending,
can_post,
can_read,
can_manage_posts,
can_manage_community,
can_manage_roles,
can_manage_questions,
);
// return
Ok(Html(
data.1.render("communities/post.html", &context).unwrap(),
data.1
.render(
if props.quotes {
"post/quotes.html"
} else {
"post/reposts.html"
},
&context,
)
.unwrap(),
))
}
@ -761,12 +902,18 @@ pub async fn question_request(
}
// ...
let ignore_users = if let Some(ref ua) = user {
data.0.get_userblocks_receivers(ua.id).await
} else {
Vec::new()
};
let feed = match data
.0
.get_posts_by_question(question.id, 12, props.page)
.await
{
Ok(p) => match data.0.fill_posts(p).await {
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
},