add: town square forum config

This commit is contained in:
trisua 2025-08-04 14:58:36 -04:00
parent d4ff681310
commit 548a6dcf4e
8 changed files with 73 additions and 5 deletions

View file

@ -119,7 +119,7 @@ pub async fn update_context_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
Json(req): Json<UpdateCommunityContext>,
Json(mut req): Json<UpdateCommunityContext>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::CommunityManage) {
@ -127,6 +127,16 @@ pub async fn update_context_request(
None => return Json(Error::NotAllowed.into()),
};
let community = match data.get_community_by_id_no_void(id).await {
Ok(x) => x,
Err(e) => return Json(e.into()),
};
if community.is_forge || community.is_forum {
req.context.enable_titles = true;
req.context.require_titles = true;
}
// check lengths
if req.context.display_name.len() > 32 {
return Json(Error::DataTooLong("display name".to_string()).into());

View file

@ -266,8 +266,12 @@ pub struct CreatePostProps {
pub from_draft: usize,
#[serde(default)]
pub quote: usize,
#[serde(default)]
pub topic: usize,
#[serde(default, alias = "sig")]
pub use_signature: bool,
#[serde(default, alias = "topics")]
pub show_topics: bool,
}
/// `/communities/intents/post`
@ -350,6 +354,20 @@ pub async fn create_post_request(
None
};
// fetch topics
let topics = if props.show_topics {
if props.community != 0 {
match data.0.get_community_by_id_no_void(props.community).await {
Ok(x) => x.topics,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
}
} else {
HashMap::new()
}
} else {
HashMap::new()
};
// ...
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
@ -361,7 +379,10 @@ pub async fn create_post_request(
context.insert("communities", &communities);
context.insert("selected_stack", &props.stack);
context.insert("selected_community", &props.community);
context.insert("selected_topic", &props.topic);
context.insert("use_signature", &props.use_signature);
context.insert("topics", &topics);
context.insert("show_topics", &props.show_topics);
// return
Ok(Html(