2018-05-16 20:20:44 +02:00
|
|
|
use activitystreams_types::activity::Create;
|
2018-05-10 11:44:57 +02:00
|
|
|
use rocket::request::Form;
|
|
|
|
use rocket::response::Redirect;
|
|
|
|
use rocket_contrib::Template;
|
|
|
|
|
2018-05-16 20:20:44 +02:00
|
|
|
use activity_pub::broadcast;
|
2018-05-10 11:44:57 +02:00
|
|
|
use db_conn::DbConn;
|
|
|
|
use models::comments::*;
|
|
|
|
use models::posts::Post;
|
|
|
|
use models::users::User;
|
|
|
|
|
|
|
|
#[get("/~/<_blog>/<slug>/comment")]
|
2018-05-10 22:31:52 +02:00
|
|
|
fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
2018-05-10 11:44:57 +02:00
|
|
|
let post = Post::find_by_slug(&*conn, slug).unwrap();
|
|
|
|
Template::render("comments/new", json!({
|
2018-05-10 16:26:12 +02:00
|
|
|
"post": post,
|
2018-05-10 22:31:52 +02:00
|
|
|
"account": user
|
2018-05-10 11:44:57 +02:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2018-05-10 16:26:12 +02:00
|
|
|
#[derive(FromForm)]
|
|
|
|
struct CommentQuery {
|
|
|
|
responding_to: Option<i32>
|
|
|
|
}
|
|
|
|
|
2018-05-10 11:44:57 +02:00
|
|
|
#[derive(FromForm)]
|
|
|
|
struct NewCommentForm {
|
2018-05-10 16:26:12 +02:00
|
|
|
pub content: String
|
2018-05-10 11:44:57 +02:00
|
|
|
}
|
|
|
|
|
2018-05-10 16:26:12 +02:00
|
|
|
#[post("/~/<blog>/<slug>/comment?<query>", data = "<data>")]
|
|
|
|
fn create(blog: String, slug: String, query: CommentQuery, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect {
|
2018-05-10 15:58:17 +02:00
|
|
|
let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
|
2018-05-10 11:44:57 +02:00
|
|
|
let form = data.get();
|
2018-05-10 15:58:17 +02:00
|
|
|
let comment = Comment::insert(&*conn, NewComment {
|
2018-05-10 11:44:57 +02:00
|
|
|
content: form.content.clone(),
|
2018-05-10 16:26:12 +02:00
|
|
|
in_response_to_id: query.responding_to,
|
2018-05-10 11:44:57 +02:00
|
|
|
post_id: post.id,
|
|
|
|
author_id: user.id,
|
|
|
|
ap_url: None,
|
|
|
|
sensitive: false,
|
|
|
|
spoiler_text: "".to_string()
|
|
|
|
});
|
2018-05-16 20:20:44 +02:00
|
|
|
// TODO: let act = Create::new(&user, &comment, &*conn);
|
|
|
|
// broadcast(&*conn, &user, act, user.get_followers(&*conn));
|
2018-05-10 17:36:32 +02:00
|
|
|
|
2018-05-10 15:58:17 +02:00
|
|
|
Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id).as_ref())
|
2018-05-10 11:44:57 +02:00
|
|
|
}
|