Remove the routes and the template for the comment form
This commit is contained in:
+1
-3
@@ -68,9 +68,6 @@ fn main() {
|
||||
routes::blogs::new_auth,
|
||||
routes::blogs::create,
|
||||
|
||||
routes::comments::new,
|
||||
routes::comments::new_response,
|
||||
routes::comments::new_auth,
|
||||
routes::comments::create,
|
||||
routes::comments::create_response,
|
||||
|
||||
@@ -85,6 +82,7 @@ fn main() {
|
||||
routes::notifications::notifications_auth,
|
||||
|
||||
routes::posts::details,
|
||||
routes::posts::details_response,
|
||||
routes::posts::activity_details,
|
||||
routes::posts::new,
|
||||
routes::posts::new_auth,
|
||||
|
||||
+3
-32
@@ -1,8 +1,7 @@
|
||||
use rocket::{
|
||||
request::Form,
|
||||
response::{Redirect, Flash}
|
||||
response::Redirect
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::{broadcast, inbox::Inbox};
|
||||
@@ -15,36 +14,9 @@ use models::{
|
||||
users::User
|
||||
};
|
||||
|
||||
use utils;
|
||||
|
||||
#[get("/~/<blog>/<slug>/comment")]
|
||||
fn new(blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
||||
new_response(blog, slug, None, user, conn)
|
||||
}
|
||||
|
||||
// See: https://github.com/SergioBenitez/Rocket/pull/454
|
||||
#[get("/~/<blog_name>/<slug>/comment?<query>")]
|
||||
fn new_response(blog_name: String, slug: String, query: Option<CommentQuery>, user: User, conn: DbConn) -> Template {
|
||||
may_fail!(Blog::find_by_fqn(&*conn, blog_name), "Couldn't find this blog", |blog| {
|
||||
may_fail!(Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| {
|
||||
Template::render("comments/new", json!({
|
||||
"post": post,
|
||||
"account": user,
|
||||
"previous": query.and_then(|q| q.responding_to.map(|r| Comment::get(&*conn, r).expect("Error retrieving previous comment").to_json(&*conn))),
|
||||
"user_fqn": user.get_fqn(&*conn)
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/comment", rank = 2)]
|
||||
fn new_auth(blog: String, slug: String) -> Flash<Redirect>{
|
||||
utils::requires_login("You need to be logged in order to post a comment", uri!(new: blog = blog, slug = slug))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct CommentQuery {
|
||||
responding_to: Option<i32>
|
||||
pub struct CommentQuery {
|
||||
pub responding_to: Option<i32>
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
@@ -71,7 +43,6 @@ fn create_response(blog_name: String, slug: String, query: Option<CommentQuery>,
|
||||
.author(user.clone())
|
||||
.create(&*conn);
|
||||
|
||||
// Comment::notify(&*conn, new_comment, user.clone().into_id());
|
||||
let instance = Instance::get_local(&*conn).unwrap();
|
||||
instance.received(&*conn, serde_json::to_value(new_comment.clone()).expect("JSON serialization error"));
|
||||
broadcast(&*conn, &user, new_comment, user.get_followers(&*conn));
|
||||
|
||||
+10
-1
@@ -14,11 +14,18 @@ use models::{
|
||||
posts::*,
|
||||
users::User
|
||||
};
|
||||
use routes::comments::CommentQuery;
|
||||
use safe_string::SafeString;
|
||||
use utils;
|
||||
|
||||
// See: https://github.com/SergioBenitez/Rocket/pull/454
|
||||
#[get("/~/<blog>/<slug>", rank = 4)]
|
||||
fn details(blog: String, slug: String, conn: DbConn, user: Option<User>) -> Template {
|
||||
details_response(blog, slug, conn, user, None)
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>?<query>")]
|
||||
fn details_response(blog: String, slug: String, conn: DbConn, user: Option<User>, query: Option<CommentQuery>) -> Template {
|
||||
may_fail!(Blog::find_by_fqn(&*conn, blog), "Couldn't find this blog", |blog| {
|
||||
may_fail!(Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| {
|
||||
let comments = Comment::list_by_post(&*conn, post.id);
|
||||
@@ -33,7 +40,9 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option<User>) -> Temp
|
||||
"n_reshares": post.get_reshares(&*conn).len(),
|
||||
"has_reshared": user.clone().map(|u| u.has_reshared(&*conn, &post)).unwrap_or(false),
|
||||
"account": user,
|
||||
"date": &post.creation_date.timestamp()
|
||||
"date": &post.creation_date.timestamp(),
|
||||
"previous": query.and_then(|q| q.responding_to.map(|r| Comment::get(&*conn, r).expect("Error retrieving previous comment").to_json(&*conn))),
|
||||
"user_fqn": user.map(|u| u.get_fqn(&*conn)).unwrap_or(String::new())
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user