From: hylom Date: Wed, 4 Oct 2017 16:58:59 +0000 (+0900) Subject: apply comment status to journal page X-Git-Tag: v0.1.1~324 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e558a63e762e2d916867f670613bf77ee576e148;p=newslash%2Fnewslash.git apply comment status to journal page --- diff --git a/src/newslash_web/lib/Newslash/Web/Controller/Journal.pm b/src/newslash_web/lib/Newslash/Web/Controller/Journal.pm index 7ecc5b2e..62973489 100644 --- a/src/newslash_web/lib/Newslash/Web/Controller/Journal.pm +++ b/src/newslash_web/lib/Newslash/Web/Controller/Journal.pm @@ -1,9 +1,12 @@ package Newslash::Web::Controller::Journal; use Mojo::Base 'Mojolicious::Controller'; -use Mojo::Util qw(dumper); +use Data::Dumper; +use List::Util qw(any); sub journal { my $c = shift; + my $users = $c->model('users'); + my $user = $c->stash('user'); my $journal_id = $c->stash('id'); my $journal = $c->model('journals')->select(id => $journal_id); if (!$journal) { @@ -11,14 +14,53 @@ sub journal { return; } my $d_id = $journal->{discussion}; + my $the_user = $users->select(uid => $journal->{uid}); + my $comments = []; my $discuss; + my $comment_allowed = 0; if ($d_id) { $discuss = $c->model('discussions')->select(id => $d_id); $comments = $c->model('comments')->select(discussion_id => $d_id); + my $relations = $c->model('relations'); + + my $status = $discuss->{commentstatus}; + my $the_uid = $the_user->{uid}; + if ($status eq "disabled") { + $comment_allowed = 0; + } + elsif ($status eq "enabled") { + $comment_allowed = 1; + } + elsif ($user->{uid} == $the_uid) { + $comment_allowed = 1; + } + elsif ($status eq "friends_only") { + $comment_allowed = 1 if $relations->is_friend(of => $the_uid, uid => $user->{uid}); + } + elsif ($status eq "friends_fof_only") { + $comment_allowed = 1 if $relations->is_fof(of => $the_uid, uid => $user->{uid}); + $comment_allowed = 1 if $relations->is_friend(of => $the_uid, uid => $user->{uid}); + } + elsif ($status eq "no_foe") { + $comment_allowed = 1 if !$relations->is_foe(of => $the_uid, uid => $user->{uid}); + } + elsif ($status eq "friends_fof_only") { + $comment_allowed = 1 if !$relations->is_foe(of => $the_uid, uid => $user->{uid}); + $comment_allowed = 1 if !$relations->is_eof(of => $the_uid, uid => $user->{uid}); + } + elsif ($status eq "logged_in") { + $comment_allowed = 1 if $user->{login}; + } } - $c->render(journal => $journal, comments => $comments); + + $c->render(journal => $journal, + discussion => $discuss, + comments => $comments, + the_user => $the_user, + comment_allowed => $comment_allowed, + ); } sub user_journals { diff --git a/src/newslash_web/public/js/comment-tree.js b/src/newslash_web/public/js/comment-tree.js index 5dcde3b3..5863e12c 100644 --- a/src/newslash_web/public/js/comment-tree.js +++ b/src/newslash_web/public/js/comment-tree.js @@ -55,6 +55,9 @@ commentTree.init = function () { }); function commentTreeCreated() { + if (!page.discussionID) { + return; + } var parentID; if (page.type == "comment") { parentID = page.commentID; diff --git a/src/newslash_web/templates/common/article/article.html.tt2 b/src/newslash_web/templates/common/article/article.html.tt2 index cda19caf..738bb7ea 100644 --- a/src/newslash_web/templates/common/article/article.html.tt2 +++ b/src/newslash_web/templates/common/article/article.html.tt2 @@ -108,7 +108,9 @@ IF story.content_type == 'poll'; url = "/poll/" _ story.id _ "/"; END; [%- END -%] [%- ELSE -%]
+ [%- IF story.discussion_id -%] [% story.commentcount %]コメント + [%- END -%]
[%- END -%] diff --git a/src/newslash_web/templates/common/js_vars.html.tt2 b/src/newslash_web/templates/common/js_vars.html.tt2 index ece9e601..da249d4c 100644 --- a/src/newslash_web/templates/common/js_vars.html.tt2 +++ b/src/newslash_web/templates/common/js_vars.html.tt2 @@ -17,6 +17,14 @@ page.sid = '[% story.sid %]'; page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %]; page.discussionID = [% story.discussion %]; + page.commentAllowed = [% IF comment_allowed; comment_allowed; ELSE; 0; END %]; + [%- END -%] + + [%- IF journal && journal.content_type == "journal" -%] + page.type = 'journal'; + page.id = [% journal.id %]; + page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %]; + page.discussionID = [% IF journal.discussion_id; journal.discussion_id; ELSE; 0; END %]; [%- END -%] [%- IF comment && comment.content_type == "comment" -%] diff --git a/src/newslash_web/templates/journal/journal.html.tt2 b/src/newslash_web/templates/journal/journal.html.tt2 index 65e12849..74daa71c 100644 --- a/src/newslash_web/templates/journal/journal.html.tt2 +++ b/src/newslash_web/templates/journal/journal.html.tt2 @@ -1,26 +1,40 @@ [% WRAPPER common/layout enable_vuejs=1 %] +[% INCLUDE common/components/comment_tree %] [% INCLUDE common/components/article_item %] - +
-
- +
+ [%- INCLUDE common/article/article story=journal hide_more_link = 1 %] + +
+ + [%- IF !journal.discussion_id -%] +
+ この投稿に対するコメントは設定により無効にされています
- [%- INCLUDE common/article/article story=journal hide_more_link = 1 %] + [%- ELSIF !comment_allowed -%] +
+ この投稿に対するコメントは一部のユーザーのみに許可されています +
+ [%- END -%] +
- [%- INCLUDE common/comment/comments -%] + +
+ +[%- INCLUDE common/sidebar mode="journal" -%] + +[% IF journal.discussion_id && comment_allowed %] +
+
+ -[%#- INCLUDE common/sidebar -%] +[%- IF user.editor || user.is_admin -%] + +[%- END -%] +[%- END -%] [% END %]