decidim-comments 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  3. data/app/assets/javascripts/decidim/comments/comments.component.js.es6 +292 -0
  4. data/app/assets/javascripts/decidim/comments/comments.component.test.js +581 -0
  5. data/app/assets/javascripts/decidim/comments/comments.js.erb +1 -1
  6. data/app/cells/decidim/comments/comment/actions.erb +7 -0
  7. data/app/cells/decidim/comments/comment/alignment_badge.erb +4 -0
  8. data/app/cells/decidim/comments/comment/author.erb +1 -0
  9. data/app/cells/decidim/comments/comment/show.erb +40 -0
  10. data/app/cells/decidim/comments/comment/utilities.erb +13 -0
  11. data/app/cells/decidim/comments/comment/votes.erb +25 -0
  12. data/app/cells/decidim/comments/comment_card_cell.rb +22 -0
  13. data/app/cells/decidim/comments/comment_cell.rb +142 -8
  14. data/app/cells/decidim/comments/comment_form/comment_as.erb +10 -0
  15. data/app/cells/decidim/comments/comment_form/show.erb +24 -0
  16. data/app/cells/decidim/comments/comment_form_cell.rb +94 -0
  17. data/app/cells/decidim/comments/comment_m/top.erb +1 -1
  18. data/app/cells/decidim/comments/comment_thread/show.erb +6 -0
  19. data/app/cells/decidim/comments/comment_thread/title.erb +3 -0
  20. data/app/cells/decidim/comments/comment_thread_cell.rb +30 -0
  21. data/app/cells/decidim/comments/comments/add_comment.erb +30 -0
  22. data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +3 -0
  23. data/app/cells/decidim/comments/comments/order_control.erb +37 -0
  24. data/app/cells/decidim/comments/comments/show.erb +32 -0
  25. data/app/cells/decidim/comments/comments/single_comment_warning.erb +9 -0
  26. data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +3 -0
  27. data/app/cells/decidim/comments/comments_cell.rb +134 -0
  28. data/app/commands/decidim/comments/vote_comment.rb +34 -10
  29. data/app/controllers/decidim/comments/application_controller.rb +16 -0
  30. data/app/controllers/decidim/comments/comments_controller.rb +122 -0
  31. data/app/controllers/decidim/comments/votes_controller.rb +41 -0
  32. data/app/events/decidim/comments/comment_created_event.rb +1 -1
  33. data/app/events/decidim/comments/comment_downvoted_event.rb +8 -0
  34. data/app/events/decidim/comments/comment_upvoted_event.rb +8 -0
  35. data/app/events/decidim/comments/comment_voted_event.rb +26 -0
  36. data/app/forms/decidim/comments/comment_form.rb +6 -2
  37. data/app/models/decidim/comments/comment.rb +22 -8
  38. data/app/models/decidim/comments/seed.rb +1 -1
  39. data/app/permissions/decidim/comments/permissions.rb +59 -0
  40. data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +2 -2
  41. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +5 -6
  42. data/app/queries/decidim/comments/sorted_comments.rb +18 -14
  43. data/app/views/decidim/comments/comments/_comment.html.erb +5 -0
  44. data/app/views/decidim/comments/comments/_comments.html.erb +1 -0
  45. data/app/views/decidim/comments/comments/create.js.erb +16 -0
  46. data/app/views/decidim/comments/comments/error.js.erb +1 -0
  47. data/app/views/decidim/comments/comments/index.js.erb +24 -0
  48. data/app/views/decidim/comments/comments/reload.js.erb +21 -0
  49. data/app/views/decidim/comments/votes/create.js.erb +23 -0
  50. data/app/views/decidim/comments/votes/error.js.erb +1 -0
  51. data/config/locales/ar.yml +0 -2
  52. data/config/locales/ca.yml +7 -2
  53. data/config/locales/cs.yml +24 -7
  54. data/config/locales/de.yml +17 -2
  55. data/config/locales/el.yml +0 -2
  56. data/config/locales/en.yml +17 -2
  57. data/config/locales/es-MX.yml +7 -2
  58. data/config/locales/es-PY.yml +7 -2
  59. data/config/locales/es.yml +7 -2
  60. data/config/locales/eu.yml +0 -2
  61. data/config/locales/fi-plain.yml +17 -2
  62. data/config/locales/fi.yml +17 -2
  63. data/config/locales/fr-CA.yml +17 -2
  64. data/config/locales/fr.yml +17 -2
  65. data/config/locales/gl.yml +7 -2
  66. data/config/locales/hu.yml +0 -2
  67. data/config/locales/id-ID.yml +0 -2
  68. data/config/locales/is-IS.yml +0 -1
  69. data/config/locales/it.yml +4 -2
  70. data/config/locales/ja.yml +8 -4
  71. data/config/locales/lv.yml +0 -2
  72. data/config/locales/nl.yml +0 -2
  73. data/config/locales/no.yml +0 -2
  74. data/config/locales/pl.yml +19 -2
  75. data/config/locales/pt-BR.yml +0 -2
  76. data/config/locales/pt.yml +0 -2
  77. data/config/locales/ro-RO.yml +0 -3
  78. data/config/locales/ru.yml +0 -2
  79. data/config/locales/sk.yml +0 -2
  80. data/config/locales/sv.yml +7 -2
  81. data/config/locales/tr-TR.yml +7 -2
  82. data/config/locales/uk.yml +0 -1
  83. data/config/locales/zh-CN.yml +0 -2
  84. data/lib/decidim/api/add_comment_type.rb +13 -0
  85. data/lib/decidim/api/comment_mutation_type.rb +22 -0
  86. data/lib/decidim/api/comment_type.rb +89 -0
  87. data/lib/decidim/api/commentable_interface.rb +50 -0
  88. data/lib/decidim/api/commentable_mutation_type.rb +30 -0
  89. data/{app/types/decidim/comments → lib/decidim/api}/commentable_type.rb +2 -5
  90. data/lib/decidim/comments/api.rb +12 -0
  91. data/lib/decidim/comments/comments_helper.rb +10 -52
  92. data/lib/decidim/comments/engine.rb +9 -7
  93. data/lib/decidim/comments/mutation_extensions.rb +22 -22
  94. data/lib/decidim/comments/query_extensions.rb +12 -14
  95. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +65 -0
  96. data/lib/decidim/comments/test.rb +1 -0
  97. data/lib/decidim/comments/version.rb +1 -1
  98. data/lib/decidim/comments.rb +1 -3
  99. metadata +67 -66
  100. data/app/assets/javascripts/decidim/comments/bundle.js +0 -268
  101. data/app/frontend/application/apollo_client.ts +0 -12
  102. data/app/frontend/application/application.component.test.tsx +0 -23
  103. data/app/frontend/application/application.component.tsx +0 -35
  104. data/app/frontend/application/icon.component.test.tsx +0 -38
  105. data/app/frontend/application/icon.component.tsx +0 -46
  106. data/app/frontend/comments/add_comment_form.component.test.tsx +0 -265
  107. data/app/frontend/comments/add_comment_form.component.tsx +0 -482
  108. data/app/frontend/comments/comment.component.test.tsx +0 -490
  109. data/app/frontend/comments/comment.component.tsx +0 -677
  110. data/app/frontend/comments/comment_order_selector.component.test.tsx +0 -29
  111. data/app/frontend/comments/comment_order_selector.component.tsx +0 -106
  112. data/app/frontend/comments/comment_thread.component.test.tsx +0 -82
  113. data/app/frontend/comments/comment_thread.component.tsx +0 -81
  114. data/app/frontend/comments/comments.component.test.tsx +0 -150
  115. data/app/frontend/comments/comments.component.tsx +0 -289
  116. data/app/frontend/comments/down_vote_button.component.test.tsx +0 -59
  117. data/app/frontend/comments/down_vote_button.component.tsx +0 -133
  118. data/app/frontend/comments/up_vote_button.component.test.tsx +0 -59
  119. data/app/frontend/comments/up_vote_button.component.tsx +0 -133
  120. data/app/frontend/comments/vote_button.component.tsx +0 -50
  121. data/app/frontend/comments/vote_button_component.test.tsx +0 -64
  122. data/app/frontend/entry.ts +0 -38
  123. data/app/frontend/entry_test.ts +0 -6
  124. data/app/frontend/fragments/add_comment_form_commentable.fragment.graphql +0 -4
  125. data/app/frontend/fragments/add_comment_form_session.fragment.graphql +0 -6
  126. data/app/frontend/fragments/comment.fragment.graphql +0 -14
  127. data/app/frontend/fragments/comment_data.fragment.graphql +0 -27
  128. data/app/frontend/fragments/comment_thread.fragment.graphql +0 -6
  129. data/app/frontend/fragments/down_vote_button.fragment.graphql +0 -6
  130. data/app/frontend/fragments/up_vote_button.fragment.graphql +0 -6
  131. data/app/frontend/mutations/add_comment.mutation.graphql +0 -9
  132. data/app/frontend/mutations/down_vote.mutation.graphql +0 -9
  133. data/app/frontend/mutations/up_vote.mutation.graphql +0 -9
  134. data/app/frontend/queries/comments.query.graphql +0 -26
  135. data/app/frontend/support/asset_url.ts +0 -11
  136. data/app/frontend/support/generate_comments_data.ts +0 -49
  137. data/app/frontend/support/generate_user_data.ts +0 -14
  138. data/app/frontend/support/generate_user_group_data.ts +0 -14
  139. data/app/frontend/support/graphql_transformer.js +0 -32
  140. data/app/frontend/support/load_translations.ts +0 -48
  141. data/app/frontend/support/require_all.ts +0 -10
  142. data/app/frontend/support/resolve_graphql_query.ts +0 -37
  143. data/app/frontend/support/schema.ts +0 -2026
  144. data/app/types/decidim/comments/commentable_interface.rb +0 -61
  145. data/app/types/decidim/comments/commentable_mutation_type.rb +0 -33
  146. data/lib/decidim/comments/api/add_comment_type.rb +0 -13
  147. data/lib/decidim/comments/api/comment_mutation_type.rb +0 -20
  148. data/lib/decidim/comments/api/comment_type.rb +0 -89
@@ -23,27 +23,51 @@ module Decidim
23
23
  #
24
24
  # Returns nothing.
25
25
  def call
26
- if @weight == 1
27
- vote = @comment.up_votes.find_by(author: @author)
28
- if vote
29
- vote.destroy!
26
+ case @weight
27
+ when 1
28
+ previous_vote = @comment.up_votes.find_by(author: @author)
29
+ if previous_vote
30
+ previous_vote.destroy!
30
31
  else
31
- @comment.up_votes.create!(author: @author)
32
+ @vote = @comment.up_votes.create!(author: @author)
32
33
  end
33
- elsif @weight == -1
34
- vote = @comment.down_votes.find_by(author: @author)
35
- if vote
36
- vote.destroy!
34
+ when -1
35
+ previous_vote = @comment.down_votes.find_by(author: @author)
36
+ if previous_vote
37
+ previous_vote.destroy!
37
38
  else
38
- @comment.down_votes.create!(author: @author)
39
+ @vote = @comment.down_votes.create!(author: @author)
39
40
  end
40
41
  else
41
42
  return broadcast(:invalid)
42
43
  end
44
+
45
+ notify_comment_author if @vote
43
46
  broadcast(:ok, @comment)
44
47
  rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
45
48
  broadcast(:invalid)
46
49
  end
50
+
51
+ def notify_comment_author
52
+ Decidim::EventsManager.publish(
53
+ event: "decidim.events.comments.comment_#{upvote? ? "upvoted" : "downvoted"}",
54
+ event_class: upvote? ? Decidim::Comments::CommentUpvotedEvent : Decidim::Comments::CommentDownvotedEvent,
55
+ resource: @comment.commentable,
56
+ affected_users: [@comment.author],
57
+ extra: {
58
+ comment_id: @comment.id,
59
+ weight: @weight,
60
+ downvotes: @comment.down_votes.count,
61
+ upvotes: @comment.up_votes.count
62
+ }
63
+ )
64
+ end
65
+
66
+ private
67
+
68
+ def upvote?
69
+ @weight.positive?
70
+ end
47
71
  end
48
72
  end
49
73
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ # This controller is the abstract class from which all other controllers of
6
+ # this engine inherit.
7
+ class ApplicationController < Decidim::ApplicationController
8
+ def permission_class_chain
9
+ [
10
+ ::Decidim::Comments::Permissions,
11
+ ::Decidim::Permissions
12
+ ]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ # Controller that manages the comments for a commentable object.
6
+ #
7
+ class CommentsController < Decidim::Comments::ApplicationController
8
+ include Decidim::ResourceHelper
9
+
10
+ before_action :authenticate_user!, only: [:create]
11
+ before_action :set_commentable
12
+ before_action :ensure_commentable!
13
+
14
+ helper_method :root_depth, :commentable, :order, :reply?, :reload?
15
+
16
+ def index
17
+ enforce_permission_to :read, :comment, commentable: commentable
18
+
19
+ @comments = SortedComments.for(
20
+ commentable,
21
+ order_by: order,
22
+ after: params.fetch(:after, 0).to_i
23
+ )
24
+ @comments_count = commentable.comments.count
25
+
26
+ respond_to do |format|
27
+ format.js do
28
+ if reload?
29
+ render :reload
30
+ else
31
+ render :index
32
+ end
33
+ end
34
+
35
+ # This makes sure bots are not causing unnecessary log entries.
36
+ format.html { redirect_to commentable_path }
37
+ end
38
+ end
39
+
40
+ def create
41
+ enforce_permission_to :create, :comment, commentable: commentable
42
+
43
+ form = Decidim::Comments::CommentForm.from_params(
44
+ params.merge(commentable: commentable)
45
+ ).with_context(
46
+ current_organization: current_organization,
47
+ current_component: commentable.component
48
+ )
49
+ Decidim::Comments::CreateComment.call(form, current_user) do
50
+ on(:ok) do |comment|
51
+ handle_success(comment)
52
+ respond_to do |format|
53
+ format.js { render :create }
54
+ end
55
+ end
56
+
57
+ on(:invalid) do
58
+ @error = t("create.error", scope: "decidim.comments.comments")
59
+ respond_to do |format|
60
+ format.js { render :error }
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ attr_reader :commentable, :comment
69
+
70
+ def set_commentable
71
+ @commentable = GlobalID::Locator.locate_signed(commentable_gid)
72
+ end
73
+
74
+ def ensure_commentable!
75
+ raise ActionController::RoutingError, "Not Found" unless commentable
76
+ end
77
+
78
+ def handle_success(comment)
79
+ @comment = comment
80
+ @comments_count = begin
81
+ case commentable
82
+ when Decidim::Comments::Comment
83
+ commentable.root_commentable.comments.count
84
+ else
85
+ commentable.comments.count
86
+ end
87
+ end
88
+ end
89
+
90
+ def commentable_gid
91
+ case action_name
92
+ when "create"
93
+ params.require(:comment).fetch(:commentable_gid)
94
+ else
95
+ params.fetch(:commentable_gid, nil)
96
+ end
97
+ end
98
+
99
+ def reply?(comment)
100
+ comment.root_commentable != comment.commentable
101
+ end
102
+
103
+ def order
104
+ params.fetch(:order, "older")
105
+ end
106
+
107
+ def reload?
108
+ params.fetch(:reload, 0).to_i == 1
109
+ end
110
+
111
+ def root_depth
112
+ params.fetch(:root_depth, 0).to_i
113
+ end
114
+
115
+ def commentable_path
116
+ return commentable.polymorphic_resource_path({}) if commentable&.respond_to?(:polymorphic_resource_path)
117
+
118
+ resource_locator(commentable).path
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ # Controller that manages the comment votes.
6
+ #
7
+ class VotesController < Decidim::Comments::ApplicationController
8
+ before_action :authenticate_user!
9
+ before_action :set_comment
10
+
11
+ helper_method :comment
12
+
13
+ def create
14
+ raise ActionController::RoutingError, "Not Found" unless comment
15
+
16
+ enforce_permission_to :vote, :comment, comment: comment
17
+
18
+ Decidim::Comments::VoteComment.call(comment, current_user, weight: params[:weight].to_i) do
19
+ on(:ok) do
20
+ respond_to do |format|
21
+ format.js { render :create }
22
+ end
23
+ end
24
+ on(:invalid) do
25
+ respond_to do |format|
26
+ format.js { render :error }
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :comment
35
+
36
+ def set_comment
37
+ @comment = Decidim::Comments::Comment.find_by(id: params[:comment_id])
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class CommentDownvotedEvent < Decidim::Comments::CommentVotedEvent
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class CommentUpvotedEvent < Decidim::Comments::CommentVotedEvent
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class CommentVotedEvent < Decidim::Events::SimpleEvent
6
+ include Decidim::Comments::CommentEvent
7
+
8
+ i18n_attributes :upvotes
9
+ i18n_attributes :downvotes
10
+
11
+ def upvotes
12
+ extra[:upvotes]
13
+ end
14
+
15
+ def downvotes
16
+ extra[:downvotes]
17
+ end
18
+
19
+ private
20
+
21
+ def resource_url_params
22
+ { anchor: "comment_#{comment.id}" }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,10 +5,11 @@ module Decidim
5
5
  # A form object used to create comments from the graphql api.
6
6
  #
7
7
  class CommentForm < Form
8
- attribute :body, String
8
+ attribute :body, Decidim::Attributes::CleanString
9
9
  attribute :alignment, Integer
10
10
  attribute :user_group_id, Integer
11
11
  attribute :commentable
12
+ attribute :commentable_gid
12
13
 
13
14
  mimic :comment
14
15
 
@@ -18,7 +19,10 @@ module Decidim
18
19
  validate :max_depth
19
20
 
20
21
  def max_length
21
- return current_component.settings.comments_max_length if current_component.try { settings.comments_max_length.positive? }
22
+ if current_component&.settings.respond_to?(:comments_max_length)
23
+ component_length = current_component.try { settings.comments_max_length.positive? }
24
+ return current_component.settings.comments_max_length if component_length
25
+ end
22
26
  return current_organization.comments_max_length if current_organization.comments_max_length.positive?
23
27
 
24
28
  1000
@@ -55,11 +55,13 @@ module Decidim
55
55
  delegate :organization, to: :commentable
56
56
 
57
57
  translatable_fields :body
58
- searchable_fields(
59
- participatory_space: :itself,
60
- A: :body,
61
- datetime: :created_at
62
- )
58
+ searchable_fields({
59
+ participatory_space: :itself,
60
+ A: :body,
61
+ datetime: :created_at
62
+ },
63
+ index_on_create: true,
64
+ index_on_update: ->(comment) { comment.visible? })
63
65
 
64
66
  def self.positive
65
67
  where(alignment: 1)
@@ -73,6 +75,10 @@ module Decidim
73
75
  where(alignment: -1)
74
76
  end
75
77
 
78
+ def visible?
79
+ participatory_space.try(:visible?) && component.try(:published?)
80
+ end
81
+
76
82
  def participatory_space
77
83
  return root_commentable if root_commentable.is_a?(Decidim::Participable)
78
84
 
@@ -130,6 +136,16 @@ module Decidim
130
136
  end
131
137
  end
132
138
 
139
+ # Public: Overrides the `reported_attributes` Reportable concern method.
140
+ def reported_attributes
141
+ [:body]
142
+ end
143
+
144
+ # Public: Overrides the `reported_searchable_content_extras` Reportable concern method.
145
+ def reported_searchable_content_extras
146
+ [normalized_author.name]
147
+ end
148
+
133
149
  def self.export_serializer
134
150
  Decidim::Comments::CommentSerializer
135
151
  end
@@ -144,8 +160,6 @@ module Decidim
144
160
  .where(decidim_commentable_id: resources.pluck(:id))
145
161
  .where(decidim_commentable_type: commentable_type)
146
162
  .where("decidim_author_type" => "Decidim::UserBaseEntity").pluck(:decidim_author_id)
147
- else
148
- []
149
163
  end
150
164
  end
151
165
 
@@ -171,7 +185,7 @@ module Decidim
171
185
  end
172
186
 
173
187
  def comment_maximum_length
174
- return unless commentable.commentable?
188
+ return 0 unless commentable.commentable?
175
189
  return component.settings.comments_max_length if component_settings_comments_max_length?
176
190
  return organization.comments_max_length if organization.comments_max_length.positive?
177
191
 
@@ -25,7 +25,7 @@ module Decidim
25
25
  params = {
26
26
  commentable: resource,
27
27
  root_commentable: resource,
28
- body: { en: ::Faker::Lorem.sentence(50) },
28
+ body: { en: ::Faker::Lorem.sentence(word_count: 50) },
29
29
  author: author,
30
30
  user_group: user_group
31
31
  }
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class Permissions < Decidim::DefaultPermissions
6
+ def permissions
7
+ return permission_action if permission_action.subject != :comment
8
+
9
+ case permission_action.action
10
+ when :read
11
+ can_read_comments?
12
+ when :create
13
+ can_create_comment?
14
+ when :vote
15
+ can_vote_comment?
16
+ end
17
+
18
+ permission_action
19
+ end
20
+
21
+ private
22
+
23
+ def can_read_comments?
24
+ return disallow! unless commentable.commentable?
25
+
26
+ allow!
27
+ end
28
+
29
+ def can_create_comment?
30
+ return disallow! unless user
31
+ return disallow! unless commentable.commentable?
32
+ return disallow! unless commentable&.user_allowed_to_comment?(user)
33
+
34
+ allow!
35
+ end
36
+
37
+ def can_vote_comment?
38
+ return disallow! unless user
39
+ return disallow! unless commentable&.user_allowed_to_comment?(user)
40
+
41
+ allow!
42
+ end
43
+
44
+ def commentable
45
+ @commentable ||= begin
46
+ if comment
47
+ comment.root_commentable
48
+ else
49
+ context.fetch(:commentable, nil)
50
+ end
51
+ end
52
+ end
53
+
54
+ def comment
55
+ @comment ||= context.fetch(:comment, nil)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -41,8 +41,8 @@ module Decidim
41
41
  user_ids = Decidim::User.where(organization: @resource.organization).pluck(:id)
42
42
  Decidim::Comments::Comment.includes(:root_commentable).not_hidden
43
43
  .where("decidim_comments_comments.created_at <= ?", end_time)
44
- .where("decidim_comments_comments.decidim_author_id IN (?)", user_ids)
45
- .where("decidim_comments_comments.decidim_author_type IN (?)", "Decidim::UserBaseEntity")
44
+ .where(decidim_comments_comments: { decidim_author_id: user_ids })
45
+ .where(decidim_comments_comments: { decidim_author_type: "Decidim::UserBaseEntity" })
46
46
  end
47
47
  end
48
48
  end
@@ -80,12 +80,11 @@ module Decidim
80
80
 
81
81
  # Gets current ParticipatorySpace of a given 'related_object'
82
82
  def retrieve_participatory_space(related_object)
83
- participatory_space = if related_object.respond_to?(:participatory_space)
84
- related_object.participatory_space
85
- elsif related_object.is_a?(Decidim::Participable)
86
- related_object
87
- end
88
- participatory_space
83
+ if related_object.respond_to?(:participatory_space)
84
+ related_object.participatory_space
85
+ elsif related_object.is_a?(Decidim::Participable)
86
+ related_object
87
+ end
89
88
  end
90
89
  end
91
90
  end
@@ -33,21 +33,25 @@ module Decidim
33
33
  scope = base_scope
34
34
  .not_hidden
35
35
  .includes(:author, :user_group, :up_votes, :down_votes)
36
+ if @options[:after]
37
+ scope = scope.where(
38
+ "decidim_comments_comments.id > ?",
39
+ @options[:after]
40
+ )
41
+ end
36
42
 
37
- scope = case @options[:order_by]
38
- when "older"
39
- order_by_older(scope)
40
- when "recent"
41
- order_by_recent(scope)
42
- when "best_rated"
43
- order_by_best_rated(scope)
44
- when "most_discussed"
45
- order_by_most_discussed(scope)
46
- else
47
- order_by_older(scope)
48
- end
49
-
50
- scope
43
+ case @options[:order_by]
44
+ when "older"
45
+ order_by_older(scope)
46
+ when "recent"
47
+ order_by_recent(scope)
48
+ when "best_rated"
49
+ order_by_best_rated(scope)
50
+ when "most_discussed"
51
+ order_by_most_discussed(scope)
52
+ else
53
+ order_by_older(scope)
54
+ end
51
55
  end
52
56
 
53
57
  private
@@ -0,0 +1,5 @@
1
+ <% if reply?(comment) %>
2
+ <%= cell("decidim/comments/comment", comment, root_depth: root_depth) %>
3
+ <% else %>
4
+ <%= cell("decidim/comments/comment_thread", comment) %>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= inline_comments_for(commentable, order: order) %>
@@ -0,0 +1,16 @@
1
+ (function() {
2
+ var rootCommentableId = <%== "comments-for-#{@comment.root_commentable.commentable_type.demodulize}-#{@comment.root_commentable.id}".to_json %>;
3
+ var commentHtml = '<%== j(render @comment).strip %>';
4
+ var inReplyTo = <%== (reply?(@comment) ? @commentable.id : nil).to_json %>;
5
+
6
+ var $comments = $("#" + rootCommentableId);
7
+ var component = $comments.data("comments");
8
+ if (inReplyTo) {
9
+ component.addReply(inReplyTo, commentHtml);
10
+ } else {
11
+ component.addThread(commentHtml);
12
+ }
13
+
14
+ // Update the comments count
15
+ $(".comments-count", $comments).text(<%== t("decidim.components.comments.title", count: @comments_count).to_json %>);
16
+ }());
@@ -0,0 +1 @@
1
+ alert("Comment creation error");
@@ -0,0 +1,24 @@
1
+ (function() {
2
+ var rootCommentableId = <%== "comments-for-#{commentable.commentable_type.demodulize}-#{commentable.id}".to_json %>;
3
+
4
+ var $comments = $("#" + rootCommentableId);
5
+ var component = $comments.data("comments");
6
+
7
+ <% @comments.each do |comment| %>
8
+ var commentId = <%= comment.id.to_json %>;
9
+ var commentHtml = '<%== j(render comment).strip %>';
10
+ var inReplyTo = <%== (reply?(comment) ? comment.commentable.id : nil).to_json %>;
11
+
12
+ var $comment = $("#comment_" + commentId);
13
+ if (1 > $comment.length) {
14
+ if (inReplyTo) {
15
+ component.addReply(inReplyTo, commentHtml);
16
+ } else {
17
+ component.addThread(commentHtml);
18
+ }
19
+ }
20
+ <% end %>
21
+
22
+ // Update the comments count
23
+ $(".comments-count", $comments).text(<%== t("decidim.components.comments.title", count: @comments_count).to_json %>);
24
+ }());
@@ -0,0 +1,21 @@
1
+ (function() {
2
+ var rootCommentableId = <%== "comments-for-#{commentable.commentable_type.demodulize}-#{commentable.id}".to_json %>;
3
+
4
+ var $comments = $("#" + rootCommentableId);
5
+ var component = $comments.data("comments");
6
+ component.unmountComponent();
7
+
8
+ var commentsHtml = '<%== j(render partial: "comments").strip %>';
9
+ $comments.replaceWith(commentsHtml);
10
+
11
+ $comments = $("#" + rootCommentableId);
12
+ $comments.foundation();
13
+
14
+ // Re-create the component
15
+ component = new Decidim.CommentsComponent($comments, $comments.data("decidim-comments"));
16
+ component.mountComponent();
17
+ $comments.data("comments", component);
18
+
19
+ // Update the comments count
20
+ $(".comments-count", $comments).text(<%== t("decidim.components.comments.title", count: @comments_count).to_json %>);
21
+ }());
@@ -0,0 +1,23 @@
1
+ (function() {
2
+ var commentId = <%= comment.id.to_json %>;
3
+ var upVotes = <%= comment.up_votes.count.to_json %>;
4
+ var downVotes = <%= comment.down_votes.count.to_json %>;
5
+ var $comment = $("#comment_" + commentId);
6
+ var $votes = $("> .comment__footer .comment__votes", $comment);
7
+ var $upVote = $(".comment__votes--up", $votes);
8
+ var $downVote = $(".comment__votes--down", $votes);
9
+
10
+ $(".comment__votes--count", $upVote).text(upVotes);
11
+ $(".comment__votes--count", $downVote).text(downVotes);
12
+
13
+ $upVote.removeClass("is-vote-selected is-vote-notselected").removeAttr("disabled");
14
+ $downVote.removeClass("is-vote-selected is-vote-notselected").removeAttr("disabled");
15
+
16
+ <% if comment.up_voted_by?(current_user) %>
17
+ $upVote.addClass("is-vote-selected");
18
+ $downVote.addClass("is-vote-notselected").attr("disabled", "disabled");
19
+ <% elsif comment.down_voted_by?(current_user) %>
20
+ $upVote.addClass("is-vote-notselected").attr("disabled", "disabled");
21
+ $downVote.addClass("is-vote-selected");
22
+ <% end %>
23
+ }());
@@ -0,0 +1 @@
1
+ alert(<%== I18n.t("votes.create.error", scope: "decidim.comments").to_json %>);
@@ -24,7 +24,6 @@ ar:
24
24
  other: الأصوات
25
25
  decidim:
26
26
  comments:
27
- comments: تعليقات
28
27
  last_activity:
29
28
  new_comment_at_html: "<span>تعليق جديد على %{link}</span>"
30
29
  votes:
@@ -81,7 +80,6 @@ ar:
81
80
  loading: جارٍ تحميل التعليقات ...
82
81
  single_comment_warning: يمكنك الإطلاع على التعليقات المتبقية الأخرى <a href="%{url}">هنا</a>.
83
82
  single_comment_warning_title: إنك ترى تعليقا واحدا
84
- title: "%{count} تعليقات"
85
83
  events:
86
84
  comments:
87
85
  comment_by_followed_user:
@@ -16,8 +16,11 @@ ca:
16
16
  other: Vots
17
17
  decidim:
18
18
  comments:
19
- comments: Comentaris
19
+ comments:
20
+ create:
21
+ error: S'ha produït un error en crear el comentari.
20
22
  comments_count: Número de comentaris
23
+ comments_title: Comentaris
21
24
  last_activity:
22
25
  new_comment_at_html: "<span>Nou comentari a %{link}</span>"
23
26
  view: Mostrar
@@ -76,7 +79,9 @@ ca:
76
79
  loading: Carregant els comentaris ...
77
80
  single_comment_warning: Pots revisar la resta de comentaris <a href="%{url}">aquí</a>.
78
81
  single_comment_warning_title: Estàs veient un sol comentari
79
- title: "%{count} comentaris"
82
+ title:
83
+ one: "%{count} comentari"
84
+ other: "%{count} comentaris"
80
85
  down_vote_button:
81
86
  text: No estic d'acord amb aquest comentari
82
87
  up_vote_button: