OSDN Git Service

apply comment status to journal page
authorhylom <hylom@users.sourceforge.jp>
Wed, 4 Oct 2017 16:58:59 +0000 (01:58 +0900)
committerhylom <hylom@users.sourceforge.jp>
Wed, 4 Oct 2017 16:58:59 +0000 (01:58 +0900)
src/newslash_web/lib/Newslash/Web/Controller/Journal.pm
src/newslash_web/public/js/comment-tree.js
src/newslash_web/templates/common/article/article.html.tt2
src/newslash_web/templates/common/js_vars.html.tt2
src/newslash_web/templates/journal/journal.html.tt2

index 7ecc5b2..6297348 100644 (file)
@@ -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 {
index 5dcde3b..5863e12 100644 (file)
@@ -55,6 +55,9 @@ commentTree.init = function () {
   });
 
   function commentTreeCreated() {
+    if (!page.discussionID) {
+      return;
+    }
     var parentID;
     if (page.type == "comment") {
       parentID = page.commentID;
index cda19ca..738bb7e 100644 (file)
@@ -108,7 +108,9 @@ IF story.content_type == 'poll'; url = "/poll/" _ story.id _ "/"; END;
     [%- 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 -%]
 
index ece9e60..da249d4 100644 (file)
   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" -%]
index 65e1284..74daa71 100644 (file)
@@ -1,26 +1,40 @@
 [% 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 %]