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:
parent
b28411da99
commit
a64c4912cf
@ -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,
|
||||
})))
|
||||
})
|
||||
}
|
||||
|
@ -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!({
|
||||
|
@ -389,6 +389,10 @@ main .article-meta .tags li a {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* New comment */
|
||||
|
||||
main .article-meta .comments form input[type="submit"]
|
||||
|
@ -60,7 +60,16 @@
|
||||
<span class="display-name">{{ comm.author.name }}</span>
|
||||
<small>@{{ comm.author.fqn }}</small>
|
||||
</a>
|
||||
<div class="text">{{ comm.content | safe }}</div>
|
||||
<div class="text">
|
||||
{% if comm.sensitive %}
|
||||
<details>
|
||||
<summary>{{ comm.spoiler_text }}</summary>
|
||||
{% endif %}
|
||||
{{ comm.content | safe }}
|
||||
{% if comm.sensitive %}
|
||||
</details>
|
||||
{% endif %}
|
||||
</div>
|
||||
<a class="button icon icon-message-circle" href="?responding_to={{ comm.id }}">{{ "Respond" | _ }}</a>
|
||||
{% for res in comm.responses %}
|
||||
{{ self::comment(comm=res) }}
|
||||
|
@ -119,6 +119,15 @@
|
||||
|
||||
{% if account %}
|
||||
<form method="post" action="{{ article.url }}comment">
|
||||
{{ macros::input(
|
||||
name="warning",
|
||||
label="Content warning",
|
||||
optional=true,
|
||||
form=comment_form,
|
||||
errors=comment_errors,
|
||||
default=default)
|
||||
}}
|
||||
|
||||
<label for="plume-editor">{{ "Your comment" | _ }}</label>
|
||||
{% if previous %}
|
||||
<input type="hidden" name="responding_to" value="{{ previous.id }}"/>
|
||||
|
Loading…
Reference in New Issue
Block a user