diff --git a/po/en.po b/po/en.po index 67cd8767..80ceeabd 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 79f89a3b..a38c24ec 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 440fa54e..5f0d98e6 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 786d2a8a..3a42db26 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 ca40a3a7..d54403cd 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 fb8c9907..7f5007ed 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 4c1bb836..00000000 --- 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 63a93f66..5f4be6c4 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 %}