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) {
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 {
});
function commentTreeCreated() {
+ if (!page.discussionID) {
+ return;
+ }
var parentID;
if (page.type == "comment") {
parentID = page.commentID;
[%- END -%]
[%- ELSE -%]
<div class="comment-counter">
+ [%- IF story.discussion_id -%]
<a href="#comments"><span class="counter" v-text="item.commentcount">[% story.commentcount %]</span>コメント</a>
+ [%- END -%]
</div>
[%- END -%]
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" -%]
[% WRAPPER common/layout enable_vuejs=1 %]
+[% INCLUDE common/components/comment_tree %]
[% INCLUDE common/components/article_item %]
-<script>
- var article = {
- type: 'journal',
- id: [% journal.id %],
- archived: [% IF journal.is_archived == 'no' %]0[% ELSE %]1[% END %],
- };
- var discussion = {
- id: [% journal.discussion %],
- };
-</script>
+
<div class="main-column">
<div class="journal main-contents" id="journal-index">
- <div class="item-wrapper">
- <article-item :item="item"></article-item>
+ <div class="journal item-wrapper">
+ [%- INCLUDE common/article/article story=journal hide_more_link = 1 %]
+ <article-item></article-item>
+ </div>
+
+ [%- IF !journal.discussion_id -%]
+ <div class="alert alert-info clear">
+ この投稿に対するコメントは設定により無効にされています
</div>
- [%- INCLUDE common/article/article story=journal hide_more_link = 1 %]
+ [%- ELSIF !comment_allowed -%]
+ <div class="alert alert-info clear">
+ この投稿に対するコメントは一部のユーザーのみに許可されています
+ </div>
+ [%- END -%]
+
</div><!-- .story -->
- [%- INCLUDE common/comment/comments -%]
+
+</div>
+
+[%- INCLUDE common/sidebar mode="journal" -%]
+
+[% IF journal.discussion_id && comment_allowed %]
+<div id="comments">
+ <comment-tree></comment-tree>
</div>
+<script>commentTree.run({el:'#comments'});</script>
-[%#- INCLUDE common/sidebar -%]
+[%- IF user.editor || user.is_admin -%]
+<script>articleItem.addTrigger('#activate-editor', {el: '#story'});</script>
+[%- END -%]
+[%- END -%]
[% END %]