add: post titles

This commit is contained in:
trisua 2025-06-08 15:34:29 -04:00
parent 1279536609
commit 5b1db42c51
14 changed files with 230 additions and 13 deletions

View file

@ -427,3 +427,29 @@ pub async fn update_membership_role(
Err(e) => Json(e.into()),
}
}
pub async fn supports_titles_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
if get_user_from_token!(jar, data).is_none() {
return Json(Error::NotAllowed.into());
}
let community = match data.get_community_by_id(id).await {
Ok(c) => c,
Err(e) => return Json(e.into()),
};
Json(ApiReturn {
ok: true,
message: if community.context.enable_titles {
"yes".to_string()
} else {
"no".to_string()
},
payload: (),
})
}

View file

@ -115,6 +115,8 @@ pub async fn create_request(
Ok(x) => x,
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
};
} else {
props.title = req.title;
}
// check sizes

View file

@ -90,6 +90,10 @@ pub fn routes() -> Router {
"/communities/{id}/banner",
get(communities::images::banner_request),
)
.route(
"/communities/{id}/supports_titles",
get(communities::communities::supports_titles_request),
)
// posts
.route("/posts", post(communities::posts::create_request))
.route("/posts/{id}", delete(communities::posts::delete_request))
@ -447,6 +451,8 @@ pub struct CreatePost {
pub answering: String,
#[serde(default)]
pub poll: Option<CreatePostPoll>,
#[serde(default)]
pub title: String,
}
#[derive(Deserialize)]