From 4c211b4308d718e468ed6b3444f5a152400b746b Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 21 Jun 2018 15:00:25 +0100 Subject: [PATCH] Remove the routes and the template for the comment form --- po/en.po | 3 +++ po/fr.po | 4 ++++ po/pl.po | 4 ++++ src/main.rs | 4 +--- src/routes/comments.rs | 35 +++---------------------------- src/routes/posts.rs | 11 +++++++++- templates/comments/new.html.tera | 16 -------------- templates/posts/details.html.tera | 2 +- 8 files changed, 26 insertions(+), 53 deletions(-) delete mode 100644 templates/comments/new.html.tera diff --git a/po/en.po b/po/en.po index 67cd876..80ceeab 100644 --- a/po/en.po +++ b/po/en.po @@ -283,3 +283,6 @@ msgstr "" msgid "{{ data }} mentioned you." msgstr "" + +msgid "Your comment" +msgstr "" diff --git a/po/fr.po b/po/fr.po index 79f89a3..a38c24e 100644 --- a/po/fr.po +++ b/po/fr.po @@ -282,3 +282,7 @@ msgstr "Vous n'êtes pas auteur dans ce blog." msgid "{{ data }} mentioned you." msgstr "" + +#, fuzzy +msgid "Your comment" +msgstr "Envoyer le commentaire" diff --git a/po/pl.po b/po/pl.po index 440fa54..5f0d98e 100644 --- a/po/pl.po +++ b/po/pl.po @@ -289,5 +289,9 @@ msgstr "" msgid "{{ data }} mentioned you." msgstr "{{ data }} skomentował Twój artykuł" +#, fuzzy +msgid "Your comment" +msgstr "Wyślij komentarz" + #~ msgid "Logowanie" #~ msgstr "Zaloguj się" diff --git a/src/main.rs b/src/main.rs index 786d2a8..3a42db2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, diff --git a/src/routes/comments.rs b/src/routes/comments.rs index ca40a3a..d54403c 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -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("/~///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("/~///comment?")] -fn new_response(blog_name: String, slug: String, query: Option, 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("/~///comment", rank = 2)] -fn new_auth(blog: String, slug: String) -> Flash{ - 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 +pub struct CommentQuery { + pub responding_to: Option } #[derive(FromForm)] @@ -71,7 +43,6 @@ fn create_response(blog_name: String, slug: String, query: Option, .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)); diff --git a/src/routes/posts.rs b/src/routes/posts.rs index fb8c990..7f5007e 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -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("/~//", rank = 4)] fn details(blog: String, slug: String, conn: DbConn, user: Option) -> Template { + details_response(blog, slug, conn, user, None) +} + +#[get("/~//?")] +fn details_response(blog: String, slug: String, conn: DbConn, user: Option, query: Option) -> 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) -> 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()) })) }) }) diff --git a/templates/comments/new.html.tera b/templates/comments/new.html.tera deleted file mode 100644 index 4c1bb83..0000000 --- a/templates/comments/new.html.tera +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "base" %} - -{% block title %} -{{ 'Comment "{{ post }}"' | _(post=post.title) }} -{% endblock title %} - -{% block content %} -

{{ 'Comment "{{ post }}"' | _(post=post.title) }}

-
- - {# Ugly, but we don't have the choice if we don't want weird paddings #} - - -
-{% endblock content %} - diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index 63a93f6..5f4be6c 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -84,7 +84,7 @@ @{{ comment.author.username }}
{{ comment.content | safe }}
- {{ "Respond" | _ }} + {{ "Respond" | _ }} {% endfor %}