Add support for CW in comments (#308)
All the backend/federation code was already, I just added the UI 🤷♀️ Fixes #253
This commit is contained in:
@@ -20,11 +20,12 @@ use plume_models::{
|
||||
users::User
|
||||
};
|
||||
|
||||
#[derive(FromForm, Debug, Validate)]
|
||||
#[derive(FromForm, Debug, Validate, Serialize)]
|
||||
struct NewCommentForm {
|
||||
pub responding_to: Option<i32>,
|
||||
#[validate(length(min = "1", message = "Your comment can't be empty"))]
|
||||
pub content: String
|
||||
pub content: String,
|
||||
pub warning: String,
|
||||
}
|
||||
|
||||
#[post("/~/<blog_name>/<slug>/comment", data = "<data>")]
|
||||
@@ -42,8 +43,8 @@ fn create(blog_name: String, slug: String, data: LenientForm<NewCommentForm>, us
|
||||
post_id: post.id,
|
||||
author_id: user.id,
|
||||
ap_url: None,
|
||||
sensitive: false,
|
||||
spoiler_text: String::new()
|
||||
sensitive: form.warning.len() > 0,
|
||||
spoiler_text: form.warning.clone()
|
||||
}).update_ap_url(&*conn);
|
||||
let new_comment = comm.create_activity(&*conn);
|
||||
|
||||
@@ -77,7 +78,8 @@ fn create(blog_name: String, slug: String, data: LenientForm<NewCommentForm>, us
|
||||
"date": &post.creation_date.timestamp(),
|
||||
"previous": form.responding_to.and_then(|r| Comment::get(&*conn, r)).map(|r| r.to_json(&*conn, &vec![])),
|
||||
"user_fqn": user.get_fqn(&*conn),
|
||||
"errors": errors
|
||||
"comment_form": form,
|
||||
"comment_errors": errors,
|
||||
})))
|
||||
})
|
||||
}
|
||||
|
||||
+9
-3
@@ -44,6 +44,8 @@ fn details_response(blog: String, slug: String, conn: DbConn, user: Option<User>
|
||||
let comments = Comment::list_by_post(&*conn, post.id);
|
||||
let comms = comments.clone();
|
||||
|
||||
let previous = query.and_then(|q| q.responding_to.map(|r| Comment::get(&*conn, r)
|
||||
.expect("posts::details_reponse: Error retrieving previous comment").to_json(&*conn, &vec![])));
|
||||
Template::render("posts/details", json!({
|
||||
"author": post.get_authors(&*conn)[0].to_json(&*conn),
|
||||
"article": post.to_json(&*conn),
|
||||
@@ -59,11 +61,15 @@ fn details_response(blog: String, slug: String, conn: DbConn, user: Option<User>
|
||||
"has_reshared": user.clone().map(|u| u.has_reshared(&*conn, &post)).unwrap_or(false),
|
||||
"account": &user.clone().map(|u| u.to_json(&*conn)),
|
||||
"date": &post.creation_date.timestamp(),
|
||||
"previous": query.and_then(|q| q.responding_to.map(|r| Comment::get(&*conn, r)
|
||||
.expect("posts::details_reponse: Error retrieving previous comment").to_json(&*conn, &vec![]))),
|
||||
"previous": previous,
|
||||
"default": {
|
||||
"warning": previous.map(|p| p["spoiler_text"].clone())
|
||||
},
|
||||
"user_fqn": user.clone().map(|u| u.get_fqn(&*conn)).unwrap_or(String::new()),
|
||||
"is_author": user.clone().map(|u| post.get_authors(&*conn).into_iter().any(|a| u.id == a.id)).unwrap_or(false),
|
||||
"is_following": user.map(|u| u.is_following(&*conn, post.get_authors(&*conn)[0].id)).unwrap_or(false)
|
||||
"is_following": user.map(|u| u.is_following(&*conn, post.get_authors(&*conn)[0].id)).unwrap_or(false),
|
||||
"comment_form": null,
|
||||
"comment_errors": null,
|
||||
}))
|
||||
} else {
|
||||
Template::render("errors/403", json!({
|
||||
|
||||
Reference in New Issue
Block a user