add: slightly more advanced theming
add: profile "before you view" warning
This commit is contained in:
parent
52ac144953
commit
2ec7e54a8e
20 changed files with 790 additions and 153 deletions
|
@ -204,6 +204,60 @@ pub async fn search_request(
|
|||
))
|
||||
}
|
||||
|
||||
/// `/communities/intents/post`
|
||||
pub async fn create_post_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let town_square = match data.0.get_community_by_id(data.0.0.town_square).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let memberships = match data.0.get_memberships_by_owner(user.id).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let mut communities: Vec<Community> = Vec::new();
|
||||
for membership in memberships {
|
||||
if membership.community == data.0.0.town_square {
|
||||
// we already pulled the town square
|
||||
continue;
|
||||
}
|
||||
|
||||
let community = match data.0.get_community_by_id(membership.community).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
communities.push(community)
|
||||
}
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("town_square", &town_square);
|
||||
context.insert("communities", &communities);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("communities/create_post.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn community_context(
|
||||
context: &mut Context,
|
||||
community: &Community,
|
||||
|
|
|
@ -46,6 +46,10 @@ pub fn routes() -> Router {
|
|||
// communities
|
||||
.route("/communities", get(communities::list_request))
|
||||
.route("/communities/search", get(communities::search_request))
|
||||
.route(
|
||||
"/communities/intents/post",
|
||||
get(communities::create_post_request),
|
||||
)
|
||||
.route("/community/{title}", get(communities::feed_request))
|
||||
.route(
|
||||
"/community/{title}/manage",
|
||||
|
@ -76,6 +80,14 @@ pub struct PaginatedQuery {
|
|||
pub page: usize,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ProfileQuery {
|
||||
#[serde(default)]
|
||||
pub page: usize,
|
||||
#[serde(default)]
|
||||
pub warning: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SearchedQuery {
|
||||
#[serde(default)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{PaginatedQuery, render_error};
|
||||
use super::{render_error, PaginatedQuery, ProfileQuery};
|
||||
use crate::{assets::initial_context, get_lang, get_user_from_token, sanitize::clean_settings, State};
|
||||
use axum::{
|
||||
Extension,
|
||||
|
@ -9,6 +9,7 @@ use axum_extra::extract::CookieJar;
|
|||
use serde::Deserialize;
|
||||
use tera::Context;
|
||||
use tetratto_core::model::{Error, auth::User, communities::Community, permissions::FinePermission};
|
||||
use tetratto_shared::hash::hash;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SettingsProps {
|
||||
|
@ -80,6 +81,7 @@ pub fn profile_context(
|
|||
context.insert("is_following", &is_following);
|
||||
context.insert("is_following_you", &is_following_you);
|
||||
context.insert("is_blocking", &is_blocking);
|
||||
context.insert("warning_hash", &hash(profile.settings.warning.clone()));
|
||||
|
||||
context.insert(
|
||||
"is_supporter",
|
||||
|
@ -99,7 +101,7 @@ pub fn profile_context(
|
|||
pub async fn posts_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
Query(props): Query<ProfileQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
|
@ -146,6 +148,19 @@ pub async fn posts_request(
|
|||
}
|
||||
}
|
||||
|
||||
// check for warning
|
||||
if props.warning {
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user).await;
|
||||
|
||||
context.insert("profile", &other_user);
|
||||
context.insert("warning_hash", &hash(other_user.settings.warning.clone()));
|
||||
|
||||
return Ok(Html(
|
||||
data.1.render("profile/warning.html", &context).unwrap(),
|
||||
));
|
||||
}
|
||||
|
||||
// fetch data
|
||||
let posts = match data
|
||||
.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue