commontator 6.0.0.pre.1 → 6.0.0.pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/commontator/application.scss +10 -3
- data/app/assets/stylesheets/commontator/comments.scss +4 -0
- data/app/controllers/commontator/comments_controller.rb +16 -4
- data/app/controllers/commontator/threads_controller.rb +1 -0
- data/app/helpers/commontator/link_renderer.rb +6 -4
- data/app/models/commontator/collection.rb +26 -0
- data/app/models/commontator/comment.rb +13 -110
- data/app/models/commontator/subscription.rb +2 -2
- data/app/models/commontator/thread.rb +102 -16
- data/app/views/commontator/comments/_body.html.erb +1 -8
- data/app/views/commontator/comments/_form.html.erb +1 -4
- data/app/views/commontator/comments/_list.html.erb +9 -5
- data/app/views/commontator/comments/_show.html.erb +85 -39
- data/app/views/commontator/comments/_show.js.erb +14 -0
- data/app/views/commontator/comments/_votes.html.erb +1 -1
- data/app/views/commontator/comments/create.js.erb +18 -13
- data/app/views/commontator/comments/delete.js.erb +9 -15
- data/app/views/commontator/comments/new.js.erb +2 -8
- data/app/views/commontator/comments/show.js.erb +30 -0
- data/app/views/commontator/comments/update.js.erb +9 -7
- data/app/views/commontator/shared/_thread.html.erb +3 -8
- data/app/views/commontator/threads/_reply.html.erb +2 -3
- data/app/views/commontator/threads/_show.html.erb +39 -42
- data/app/views/commontator/threads/_show.js.erb +5 -5
- data/app/views/commontator/threads/show.js.erb +3 -2
- data/config/initializers/commontator.rb +9 -6
- data/config/locales/de.yml +10 -2
- data/config/locales/en.yml +10 -2
- data/config/locales/pt-BR.yml +10 -2
- data/config/locales/ru.yml +10 -2
- data/config/locales/zh.yml +12 -4
- data/config/routes.rb +9 -9
- data/db/migrate/1_add_replying_to_comments.rb +0 -2
- data/lib/commontator.rb +1 -0
- data/lib/commontator/commontable_config.rb +6 -1
- data/lib/commontator/commontator_config.rb +1 -1
- data/lib/commontator/config.rb +2 -2
- data/lib/commontator/controllers.rb +3 -8
- data/lib/commontator/shared_helper.rb +0 -1
- data/lib/commontator/version.rb +1 -1
- metadata +13 -12
- data/app/views/commontator/comments/_actions.html.erb +0 -28
- data/app/views/commontator/comments/_reply.html.erb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b104df98e58a375c90e006da5b5dfe15833cbc12bd8bc19a1c7deb5fe47fb50
|
4
|
+
data.tar.gz: f7b5f7d780315910e49e6989f58d98d2bf085dcd27007086ec1c4554b7f1d0a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f7eeda6f7d0208640dbe86a98b047ae1092460836bbf8d1d13e200993aad7dc505e12fb793bdfc4fca9aff1c01498ea479368772022c1b6e47a65b0636f8af
|
7
|
+
data.tar.gz: b0db208a7f29d5d3ab311c2ec9d044c86a205e08c79b335621e70a2b9af1027b3c146356b121d768c02c63f85708e57f453a51fe4b15d70523f1e1534b0afb7a
|
@@ -37,10 +37,13 @@
|
|
37
37
|
background-color: #FFF;
|
38
38
|
}
|
39
39
|
|
40
|
+
.children {
|
41
|
+
padding-left: 15px;
|
42
|
+
}
|
43
|
+
|
40
44
|
/* Modified from: https://www.strangerstudios.com/sandbox/pagination/diggstyle.php */
|
41
45
|
.page-entries-info, .will-paginate {
|
42
|
-
margin
|
43
|
-
margin-bottom: 10px;
|
46
|
+
margin: 10px 0;
|
44
47
|
}
|
45
48
|
|
46
49
|
.pagination {
|
@@ -70,7 +73,11 @@
|
|
70
73
|
color: #FFF;
|
71
74
|
}
|
72
75
|
|
73
|
-
|
76
|
+
.name {
|
77
|
+
margin: 2px 9px 2px 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
.disabled {
|
74
81
|
margin-right: 4px;
|
75
82
|
border: 1px solid #EEE;
|
76
83
|
padding: 2px 5px 2px 5px;
|
@@ -1,6 +1,15 @@
|
|
1
1
|
class Commontator::CommentsController < Commontator::ApplicationController
|
2
|
-
before_action :set_thread,
|
2
|
+
before_action :set_thread, only: [ :new, :create ]
|
3
3
|
before_action :set_comment_and_thread, except: [ :new, :create ]
|
4
|
+
before_action :commontator_set_thread_variables, only: [ :show, :update, :delete, :undelete ]
|
5
|
+
|
6
|
+
# GET /comments/1
|
7
|
+
def show
|
8
|
+
respond_to do |format|
|
9
|
+
format.html { redirect_to commontable_url }
|
10
|
+
format.js
|
11
|
+
end
|
12
|
+
end
|
4
13
|
|
5
14
|
# GET /threads/1/comments/new
|
6
15
|
def new
|
@@ -13,7 +22,7 @@ class Commontator::CommentsController < Commontator::ApplicationController
|
|
13
22
|
Commontator.commontator_name(parent.creator)
|
14
23
|
}</span>\n#{
|
15
24
|
parent.body
|
16
|
-
}\n</blockquote>\n" if @commontator_thread.config.comment_reply_style
|
25
|
+
}\n</blockquote>\n" if [ :q, :b ].include? @commontator_thread.config.comment_reply_style
|
17
26
|
end
|
18
27
|
security_transgression_unless @comment.can_be_created_by?(@commontator_user)
|
19
28
|
|
@@ -39,6 +48,9 @@ class Commontator::CommentsController < Commontator::ApplicationController
|
|
39
48
|
@commontator_thread.subscribe(@commontator_user) if sub == :a || sub == :b
|
40
49
|
subscribe_mentioned if @commontator_thread.config.mentions_enabled
|
41
50
|
Commontator::Subscription.comment_created(@comment)
|
51
|
+
@commontator_page = @commontator_thread.new_comment_page(
|
52
|
+
@comment.parent_id, @commontator_show_all
|
53
|
+
)
|
42
54
|
|
43
55
|
format.js
|
44
56
|
else
|
@@ -156,12 +168,12 @@ class Commontator::CommentsController < Commontator::ApplicationController
|
|
156
168
|
def set_comment_and_thread
|
157
169
|
@comment = Commontator::Comment.find(params[:id])
|
158
170
|
@commontator_thread = @comment.thread
|
159
|
-
commontator_set_new_comment
|
160
171
|
end
|
161
172
|
|
162
173
|
def subscribe_mentioned
|
163
174
|
Commontator.commontator_mentions(@commontator_user, @commontator_thread, '')
|
164
|
-
.where(id: params[:mentioned_ids])
|
175
|
+
.where(id: params[:mentioned_ids])
|
176
|
+
.each do |user|
|
165
177
|
@commontator_thread.subscribe(user)
|
166
178
|
end
|
167
179
|
end
|
@@ -2,6 +2,7 @@ class Commontator::ThreadsController < Commontator::ApplicationController
|
|
2
2
|
skip_before_action :ensure_user, only: :show
|
3
3
|
before_action :set_thread
|
4
4
|
before_action :commontator_set_thread_variables, except: :mentions
|
5
|
+
before_action :commontator_set_new_comment, only: [ :show, :reopen ]
|
5
6
|
|
6
7
|
# GET /threads/1
|
7
8
|
def show
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require 'will_paginate'
|
2
|
-
|
3
1
|
class Commontator::LinkRenderer < WillPaginate::ActionView::LinkRenderer
|
4
2
|
protected
|
5
3
|
|
4
|
+
def html_container(html)
|
5
|
+
html = "<span class=\"name\">#{@options[:name]}</span>#{html}" if @options[:name]
|
6
|
+
tag(:div, html, container_attributes)
|
7
|
+
end
|
8
|
+
|
6
9
|
def url(page)
|
7
10
|
@base_url_params ||= begin
|
8
11
|
url_params = merge_get_params(default_url_params)
|
@@ -12,8 +15,7 @@ class Commontator::LinkRenderer < WillPaginate::ActionView::LinkRenderer
|
|
12
15
|
url_params = @base_url_params.dup
|
13
16
|
add_current_page_param(url_params, page)
|
14
17
|
|
15
|
-
|
16
|
-
routes_proxy.url_for(url_params)
|
18
|
+
@template.commontator.url_for(url_params)
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Commontator::Collection < WillPaginate::Collection
|
2
|
+
attr_reader :root_per_page
|
3
|
+
|
4
|
+
# This method determines if we are in a shorter version of the first page, which we call page 0
|
5
|
+
def page_zero?
|
6
|
+
total_entries > @per_page && @per_page < @root_per_page
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(array, count, root_per_page, per_page, page = 1)
|
10
|
+
self.total_entries = count
|
11
|
+
@root_per_page = root_per_page
|
12
|
+
@per_page = per_page
|
13
|
+
@current_page = page_zero? ? 0 : WillPaginate::PageNumber(page)
|
14
|
+
@first_call = true
|
15
|
+
|
16
|
+
replace(array)
|
17
|
+
end
|
18
|
+
|
19
|
+
# We return 2 total_pages under certain conditions to trick will_paginate
|
20
|
+
# into rendering the pagination controls when it otherwise wouldn't
|
21
|
+
def total_pages
|
22
|
+
min_total_pages = page_zero? && @first_call ? 2 : 1
|
23
|
+
@first_call = false
|
24
|
+
[ (total_entries.to_f/@root_per_page).ceil, min_total_pages ].max
|
25
|
+
end
|
26
|
+
end
|
@@ -4,30 +4,14 @@ class Commontator::Comment < ActiveRecord::Base
|
|
4
4
|
belongs_to :thread, inverse_of: :comments
|
5
5
|
belongs_to :parent, optional: true, class_name: name, inverse_of: :children
|
6
6
|
|
7
|
-
has_many :children, class_name: name, inverse_of: :parent
|
8
|
-
|
9
|
-
serialize :ancestor_ids, Commontator::JsonArrayCoder
|
10
|
-
serialize :descendant_ids, Commontator::JsonArrayCoder
|
7
|
+
has_many :children, class_name: name, foreign_key: :parent_id, inverse_of: :parent
|
11
8
|
|
12
9
|
validates :editor, presence: true, on: :update
|
13
10
|
validates :body, presence: true, uniqueness: {
|
14
|
-
scope: [ :creator_type, :creator_id, :thread_id, :deleted_at ],
|
15
|
-
message: I18n.t('commontator.comment.errors.double_posted')
|
11
|
+
scope: [ :creator_type, :creator_id, :thread_id, :deleted_at ], message: :double_posted
|
16
12
|
}
|
17
13
|
validate :parent_is_not_self, :parent_belongs_to_the_same_thread, if: :parent
|
18
14
|
|
19
|
-
before_save :set_ancestor_ids_and_ancestor_descendant_ids
|
20
|
-
before_destroy :remove_ancestor_descendant_ids
|
21
|
-
|
22
|
-
cattr_accessor :will_paginate
|
23
|
-
self.will_paginate = begin
|
24
|
-
require 'will_paginate'
|
25
|
-
|
26
|
-
true
|
27
|
-
rescue LoadError
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
15
|
cattr_accessor :is_votable
|
32
16
|
self.is_votable = begin
|
33
17
|
require 'acts_as_votable'
|
@@ -38,10 +22,6 @@ class Commontator::Comment < ActiveRecord::Base
|
|
38
22
|
false
|
39
23
|
end
|
40
24
|
|
41
|
-
def self.will_paginate?
|
42
|
-
will_paginate
|
43
|
-
end
|
44
|
-
|
45
25
|
def self.is_votable?
|
46
26
|
is_votable
|
47
27
|
end
|
@@ -51,13 +31,14 @@ class Commontator::Comment < ActiveRecord::Base
|
|
51
31
|
end
|
52
32
|
|
53
33
|
def is_latest?
|
54
|
-
thread.
|
34
|
+
thread.latest_comment(false) == self
|
55
35
|
end
|
56
36
|
|
57
37
|
def get_vote_by(user)
|
58
38
|
return nil unless self.class.is_votable? && !user.nil? && user.is_commontator
|
59
39
|
|
60
|
-
|
40
|
+
# Preloaded with a condition in thread#nested_comments_for
|
41
|
+
votes_for.to_a.find { |vote| vote.voter_id == user.id && vote.voter_type == user.class.name }
|
61
42
|
end
|
62
43
|
|
63
44
|
def update_cached_votes(vote_scope = nil)
|
@@ -85,6 +66,12 @@ class Commontator::Comment < ActiveRecord::Base
|
|
85
66
|
self.save
|
86
67
|
end
|
87
68
|
|
69
|
+
def body
|
70
|
+
is_deleted? ? I18n.t(
|
71
|
+
'commontator.comment.status.deleted_by', deleter_name: Commontator.commontator_name(editor)
|
72
|
+
) : super
|
73
|
+
end
|
74
|
+
|
88
75
|
def created_timestamp
|
89
76
|
I18n.t 'commontator.comment.status.created_at',
|
90
77
|
created_at: I18n.l(created_at, format: :commontator)
|
@@ -124,8 +111,7 @@ class Commontator::Comment < ActiveRecord::Base
|
|
124
111
|
end
|
125
112
|
|
126
113
|
def can_be_voted_on?
|
127
|
-
!thread.is_closed? && !is_deleted? &&
|
128
|
-
thread.config.comment_voting.to_sym != :n && self.class.is_votable?
|
114
|
+
!thread.is_closed? && !is_deleted? && thread.is_votable? && self.class.is_votable?
|
129
115
|
end
|
130
116
|
|
131
117
|
def can_be_voted_on_by?(user)
|
@@ -135,6 +121,7 @@ class Commontator::Comment < ActiveRecord::Base
|
|
135
121
|
|
136
122
|
protected
|
137
123
|
|
124
|
+
# These 2 validation messages are not currently translated because end users should never see them
|
138
125
|
def parent_is_not_self
|
139
126
|
return if parent != self
|
140
127
|
errors.add :parent, 'must be a different comment'
|
@@ -146,88 +133,4 @@ class Commontator::Comment < ActiveRecord::Base
|
|
146
133
|
errors.add :parent, 'must belong to the same thread'
|
147
134
|
throw :abort
|
148
135
|
end
|
149
|
-
|
150
|
-
def remove_ancestor_descendant_ids
|
151
|
-
return if ancestor_ids.empty?
|
152
|
-
|
153
|
-
# Remove id and descendant_ids from ancestors
|
154
|
-
self.class.where(id: ancestor_ids).order(:id).update_all("descendant_ids = #{
|
155
|
-
([ id ] + descendant_ids).reduce(self.class.arel_table[:descendant_ids]) do |memo, descendant_id|
|
156
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
157
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
158
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
159
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
160
|
-
memo, Arel::Nodes.build_quoted("[#{descendant_id}]"), Arel::Nodes.build_quoted('[]')
|
161
|
-
]), Arel::Nodes.build_quoted("[#{descendant_id},"), Arel::Nodes.build_quoted('[')
|
162
|
-
]), Arel::Nodes.build_quoted(",#{descendant_id},"), Arel::Nodes.build_quoted(',')
|
163
|
-
]), Arel::Nodes.build_quoted(",#{descendant_id}]"), Arel::Nodes.build_quoted(']')
|
164
|
-
])
|
165
|
-
end.to_sql
|
166
|
-
}")
|
167
|
-
|
168
|
-
association(:parent).reset
|
169
|
-
end
|
170
|
-
|
171
|
-
def set_ancestor_ids_and_ancestor_descendant_ids
|
172
|
-
return if ancestor_ids.first == parent_id
|
173
|
-
|
174
|
-
pa = parent
|
175
|
-
|
176
|
-
remove_ancestor_descendant_ids
|
177
|
-
|
178
|
-
# Remove ancestor_ids from descendants
|
179
|
-
unless ancestor_ids.empty? || descendant_ids.empty?
|
180
|
-
self.class.where(id: descendant_ids).order(:id).update_all("ancestor_ids = #{
|
181
|
-
ancestor_ids.reduce(self.class.arel_table[:ancestor_ids]) do |memo, ancestor_id|
|
182
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
183
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
184
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
185
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
186
|
-
memo, Arel::Nodes.build_quoted("[#{ancestor_id}]"), Arel::Nodes.build_quoted('[]')
|
187
|
-
]), Arel::Nodes.build_quoted("[#{ancestor_id},"), Arel::Nodes.build_quoted('[')
|
188
|
-
]), Arel::Nodes.build_quoted(",#{ancestor_id},"), Arel::Nodes.build_quoted(',')
|
189
|
-
]), Arel::Nodes.build_quoted(",#{ancestor_id}]"), Arel::Nodes.build_quoted(']')
|
190
|
-
])
|
191
|
-
end.to_sql
|
192
|
-
}")
|
193
|
-
|
194
|
-
children.reset
|
195
|
-
end
|
196
|
-
|
197
|
-
if pa.nil?
|
198
|
-
self.ancestor_ids = []
|
199
|
-
else
|
200
|
-
self.ancestor_ids = [ pa.id ] + pa.ancestor_ids
|
201
|
-
|
202
|
-
# Add id and descendant_ids to ancestors
|
203
|
-
descendant_ids_str = ([ id ] + descendant_ids).to_json[1..-2]
|
204
|
-
self.class.where(id: ancestor_ids).order(:id).update_all("descendant_ids = #{
|
205
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
206
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
207
|
-
Arel::Nodes::NamedFunction.new('COALESCE', [
|
208
|
-
self.class.arel_table[:descendant_ids], Arel::Nodes.build_quoted('[]')
|
209
|
-
]), Arel::Nodes.build_quoted(']'), Arel::Nodes.build_quoted(",#{descendant_ids_str}]")
|
210
|
-
]), Arel::Nodes.build_quoted('[,'), Arel::Nodes.build_quoted('[')
|
211
|
-
]).to_sql
|
212
|
-
}")
|
213
|
-
|
214
|
-
association(:parent).reset
|
215
|
-
|
216
|
-
# Add ancestor_ids to descendants
|
217
|
-
unless descendant_ids.empty?
|
218
|
-
ancestor_ids_str = ancestor_ids.to_json[1..-2]
|
219
|
-
self.class.where(id: descendant_ids).order(:id).update_all("ancestor_ids = #{
|
220
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
221
|
-
Arel::Nodes::NamedFunction.new('REPLACE', [
|
222
|
-
Arel::Nodes::NamedFunction.new('COALESCE', [
|
223
|
-
self.class.arel_table[:ancestor_ids], Arel::Nodes.build_quoted('[]')
|
224
|
-
]), Arel::Nodes.build_quoted(']'), Arel::Nodes.build_quoted(",#{ancestor_ids_str}]")
|
225
|
-
]), Arel::Nodes.build_quoted('[,'), Arel::Nodes.build_quoted('[')
|
226
|
-
]).to_sql
|
227
|
-
}")
|
228
|
-
|
229
|
-
children.reset
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
136
|
end
|
@@ -12,8 +12,8 @@ class Commontator::Subscription < ActiveRecord::Base
|
|
12
12
|
mail.respond_to?(:deliver_later) ? mail.deliver_later : mail.deliver
|
13
13
|
end
|
14
14
|
|
15
|
-
def unread_comments
|
15
|
+
def unread_comments(show_all)
|
16
16
|
created_at = Commontator::Comment.arel_table[:created_at]
|
17
|
-
thread.filtered_comments.where(created_at.gteq(updated_at))
|
17
|
+
thread.filtered_comments(show_all).where(created_at.gteq(updated_at))
|
18
18
|
end
|
19
19
|
end
|
@@ -12,23 +12,25 @@ class Commontator::Thread < ActiveRecord::Base
|
|
12
12
|
@config ||= commontable.try(:commontable_config) || Commontator
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def is_votable?
|
16
|
+
config.comment_voting.to_sym != :n
|
17
17
|
end
|
18
18
|
|
19
19
|
def is_filtered?
|
20
20
|
!config.comment_filter.nil?
|
21
21
|
end
|
22
22
|
|
23
|
-
def filtered_comments
|
23
|
+
def filtered_comments(show_all)
|
24
|
+
return comments if show_all
|
25
|
+
|
24
26
|
cf = config.comment_filter
|
25
27
|
return comments if cf.nil?
|
26
28
|
|
27
29
|
comments.where(cf)
|
28
30
|
end
|
29
31
|
|
30
|
-
def ordered_comments(show_all
|
31
|
-
vc = show_all
|
32
|
+
def ordered_comments(show_all)
|
33
|
+
vc = filtered_comments(show_all)
|
32
34
|
cc = Commontator::Comment.arel_table
|
33
35
|
case config.comment_order.to_sym
|
34
36
|
when :l
|
@@ -44,32 +46,116 @@ class Commontator::Thread < ActiveRecord::Base
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
def
|
49
|
+
def latest_comment(show_all)
|
50
|
+
@latest_comment ||= ordered_comments(show_all).last
|
51
|
+
end
|
52
|
+
|
53
|
+
def comments_with_parent_id(parent_id, show_all)
|
48
54
|
oc = ordered_comments(show_all)
|
49
|
-
|
55
|
+
[ :i, :b ].include?(config.comment_reply_style) ? oc.where(parent_id: parent_id) : oc
|
56
|
+
end
|
57
|
+
|
58
|
+
def paginated_comments(page = 1, parent_id, show_all)
|
59
|
+
cp = comments_with_parent_id(parent_id, show_all)
|
60
|
+
|
61
|
+
cp.paginate(page: page, per_page: config.comments_per_page[0])
|
62
|
+
end
|
63
|
+
|
64
|
+
def nest_comments(
|
65
|
+
comments, root_per_page, per_page_by_parent_id, count_by_parent_id, children_by_parent_id
|
66
|
+
)
|
67
|
+
comments.map do |comment|
|
68
|
+
# Delete is used to ensure loops don't cause stack overflow
|
69
|
+
children = children_by_parent_id.delete(comment.id) || []
|
70
|
+
count = count_by_parent_id.delete(comment.id) || 0
|
71
|
+
per_page = per_page_by_parent_id.delete(comment.id) || 0
|
72
|
+
nested_children = nest_comments(
|
73
|
+
children, root_per_page, per_page_by_parent_id, count_by_parent_id, children_by_parent_id
|
74
|
+
)
|
50
75
|
|
51
|
-
|
76
|
+
[ comment, Commontator::Collection.new(nested_children, count, root_per_page, per_page) ]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def nested_comments_for(user, comments, show_all)
|
81
|
+
includes = [ :thread, :creator, :editor ]
|
82
|
+
total_entries = comments.total_entries
|
83
|
+
root_per_page = config.comments_per_page[0]
|
84
|
+
current_page = comments.current_page.to_i
|
85
|
+
comments = comments.includes(includes).to_a
|
86
|
+
count_by_parent_id = {}
|
87
|
+
per_page_by_parent_id = {}
|
88
|
+
children_by_parent_id = Hash.new { |hash, key| hash[key] = [] }
|
89
|
+
|
90
|
+
if [ :i, :b ].include? config.comment_reply_style
|
91
|
+
all_parent_ids = comments.map(&:id)
|
92
|
+
(config.comments_per_page[1..-1] + [ 0 ]).each_with_index do |per_page, index|
|
93
|
+
ordered_comments(show_all).where(parent_id: all_parent_ids)
|
94
|
+
.group(:parent_id)
|
95
|
+
.count
|
96
|
+
.each do |parent_id, count|
|
97
|
+
count_by_parent_id[parent_id] = count
|
98
|
+
per_page_by_parent_id[parent_id] = per_page
|
99
|
+
end
|
100
|
+
|
101
|
+
next if per_page == 0
|
102
|
+
|
103
|
+
children = all_parent_ids.empty? ? [] : Commontator::Comment.find_by_sql(
|
104
|
+
all_parent_ids.map do |parent_id|
|
105
|
+
Commontator::Comment.select(Arel.star).from(
|
106
|
+
Arel::Nodes::Grouping.new(
|
107
|
+
Arel::Nodes::SqlLiteral.new(
|
108
|
+
ordered_comments(show_all).where(parent_id: parent_id).limit(per_page).to_sql
|
109
|
+
)
|
110
|
+
)
|
111
|
+
).to_sql
|
112
|
+
end.reduce { |memo, sql| memo.nil? ? sql : "#{memo} UNION ALL #{sql}" }
|
113
|
+
)
|
114
|
+
children.each { |comment| children_by_parent_id[comment.parent_id] << comment }
|
115
|
+
all_parent_ids = children.map(&:id)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
Commontator::Collection.new(
|
120
|
+
nest_comments(
|
121
|
+
comments, root_per_page, per_page_by_parent_id, count_by_parent_id, children_by_parent_id
|
122
|
+
),
|
123
|
+
total_entries,
|
124
|
+
root_per_page,
|
125
|
+
root_per_page,
|
126
|
+
current_page
|
127
|
+
).tap do |nested_comments|
|
128
|
+
next unless is_votable?
|
129
|
+
|
130
|
+
ActiveRecord::Associations::Preloader.new.preload(
|
131
|
+
nested_comments.flatten, :votes_for, ActsAsVotable::Vote.where(voter: user)
|
132
|
+
)
|
133
|
+
end
|
52
134
|
end
|
53
135
|
|
54
|
-
def new_comment_page(
|
55
|
-
|
136
|
+
def new_comment_page(parent_id, show_all)
|
137
|
+
per_page = config.comments_per_page[0].to_i
|
138
|
+
return 1 if per_page <= 0
|
56
139
|
|
140
|
+
comment_order = config.comment_order.to_sym
|
141
|
+
return 1 if comment_order == :l
|
142
|
+
|
143
|
+
cp = comments_with_parent_id(parent_id, show_all)
|
144
|
+
cc = Commontator::Comment.arel_table
|
57
145
|
comment_index = case config.comment_order.to_sym
|
58
146
|
when :l
|
59
147
|
1 # First comment
|
60
148
|
when :ve
|
61
|
-
cc = Commontator::Comment.arel_table
|
62
149
|
# Last comment with rating == 0
|
63
|
-
|
150
|
+
cp.where((cc[:cached_votes_up] - cc[:cached_votes_down]).gteq(0)).count
|
64
151
|
when :vl
|
65
|
-
cc = Commontator::Comment.arel_table
|
66
152
|
# First comment with rating == 0
|
67
|
-
|
153
|
+
cp.where((cc[:cached_votes_up] - cc[:cached_votes_down]).gt(0)).count + 1
|
68
154
|
else
|
69
|
-
|
155
|
+
cp.count # Last comment
|
70
156
|
end
|
71
157
|
|
72
|
-
(comment_index.to_f/per_page
|
158
|
+
(comment_index.to_f/per_page).ceil
|
73
159
|
end
|
74
160
|
|
75
161
|
def is_closed?
|