decidim-comments 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/comments/bundle.js +53 -53
  3. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  4. data/app/cells/decidim/comments/comment_activity_cell.rb +2 -22
  5. data/app/cells/decidim/comments/comment_cell.rb +22 -0
  6. data/app/cells/decidim/comments/comment_m/footer.erb +5 -0
  7. data/app/cells/decidim/comments/comment_m/top.erb +7 -0
  8. data/app/cells/decidim/comments/comment_m_cell.rb +29 -0
  9. data/app/commands/decidim/comments/create_comment.rb +1 -1
  10. data/app/forms/decidim/comments/comment_form.rb +8 -1
  11. data/app/frontend/comments/add_comment_form.component.test.tsx +30 -28
  12. data/app/frontend/comments/add_comment_form.component.tsx +32 -16
  13. data/app/frontend/comments/comment.component.test.tsx +35 -4
  14. data/app/frontend/comments/comment.component.tsx +24 -15
  15. data/app/frontend/comments/comment_thread.component.test.tsx +9 -8
  16. data/app/frontend/comments/comment_thread.component.tsx +3 -1
  17. data/app/frontend/comments/comments.component.test.tsx +17 -14
  18. data/app/frontend/comments/comments.component.tsx +28 -4
  19. data/app/frontend/comments/down_vote_button.component.tsx +24 -9
  20. data/app/frontend/comments/up_vote_button.component.tsx +24 -9
  21. data/app/frontend/mutations/add_comment.mutation.graphql +2 -2
  22. data/app/frontend/mutations/down_vote.mutation.graphql +2 -2
  23. data/app/frontend/mutations/up_vote.mutation.graphql +2 -2
  24. data/app/frontend/queries/comments.query.graphql +2 -2
  25. data/app/frontend/support/schema.ts +1060 -735
  26. data/app/helpers/decidim/comments/comment_cells_helper.rb +33 -0
  27. data/app/models/decidim/comments/comment.rb +73 -20
  28. data/app/models/decidim/comments/seed.rb +1 -1
  29. data/app/types/decidim/comments/commentable_interface.rb +1 -1
  30. data/app/types/decidim/comments/commentable_mutation_type.rb +4 -1
  31. data/config/locales/am-ET.yml +1 -0
  32. data/config/locales/bg.yml +6 -0
  33. data/config/locales/ca.yml +1 -0
  34. data/config/locales/cs.yml +1 -0
  35. data/config/locales/da.yml +1 -0
  36. data/config/locales/en.yml +1 -0
  37. data/config/locales/eo.yml +1 -0
  38. data/config/locales/es-MX.yml +1 -0
  39. data/config/locales/es-PY.yml +1 -0
  40. data/config/locales/es.yml +3 -2
  41. data/config/locales/et.yml +1 -0
  42. data/config/locales/fi-plain.yml +1 -0
  43. data/config/locales/fi.yml +2 -1
  44. data/config/locales/fr-CA.yml +2 -1
  45. data/config/locales/fr.yml +2 -1
  46. data/config/locales/hr.yml +1 -0
  47. data/config/locales/hu.yml +1 -1
  48. data/config/locales/is-IS.yml +0 -2
  49. data/config/locales/is.yml +76 -0
  50. data/config/locales/ja-JP.yml +2 -2
  51. data/config/locales/ja.yml +121 -0
  52. data/config/locales/ko-KR.yml +1 -0
  53. data/config/locales/ko.yml +1 -0
  54. data/config/locales/lt.yml +1 -0
  55. data/config/locales/{lv-LV.yml → lv.yml} +0 -0
  56. data/config/locales/mt.yml +1 -0
  57. data/config/locales/nl.yml +3 -2
  58. data/config/locales/om-ET.yml +1 -0
  59. data/config/locales/pl.yml +5 -5
  60. data/config/locales/so-SO.yml +1 -0
  61. data/config/locales/sv.yml +1 -0
  62. data/config/locales/ti-ER.yml +1 -0
  63. data/config/locales/uk.yml +0 -1
  64. data/config/locales/vi-VN.yml +1 -0
  65. data/config/locales/vi.yml +1 -0
  66. data/config/locales/zh-CN.yml +121 -0
  67. data/config/locales/zh-TW.yml +1 -0
  68. data/db/migrate/20200706123136_make_comments_handle_i18n.rb +41 -0
  69. data/db/migrate/20200828101910_add_commentable_counter_cache_to_comments.rb +9 -0
  70. data/lib/decidim/comments/api/comment_type.rb +5 -1
  71. data/lib/decidim/comments/comment_serializer.rb +7 -2
  72. data/lib/decidim/comments/comment_vote_serializer.rb +5 -1
  73. data/lib/decidim/comments/commentable.rb +11 -0
  74. data/lib/decidim/comments/comments_helper.rb +28 -4
  75. data/lib/decidim/comments/engine.rb +13 -0
  76. data/lib/decidim/comments/mutation_extensions.rb +8 -0
  77. data/lib/decidim/comments/query_extensions.rb +4 -0
  78. data/lib/decidim/comments/test/factories.rb +10 -1
  79. data/lib/decidim/comments/test/shared_examples/comment_event.rb +1 -1
  80. data/lib/decidim/comments/version.rb +1 -1
  81. metadata +37 -11
@@ -37,7 +37,11 @@ module Decidim
37
37
  private
38
38
 
39
39
  def root_commentable_url
40
- @root_commentable_url ||= Decidim::ResourceLocatorPresenter.new(resource.comment.root_commentable).url
40
+ @root_commentable_url ||= if resource.comment.root_commentable&.respond_to?(:polymorphic_resource_url)
41
+ resource.comment.root_commentable.polymorphic_resource_url
42
+ else
43
+ ResourceLocatorPresenter.new(resource.comment.root_commentable).url
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -51,6 +51,17 @@ module Decidim
51
51
  def user_allowed_to_comment?(_user)
52
52
  true
53
53
  end
54
+
55
+ # Public: Updates the comments counter cache. We have to do it these
56
+ # way in order to properly calculate the coutner with hidden
57
+ # comments.
58
+ #
59
+ # rubocop:disable Rails/SkipsModelValidations
60
+ def update_comments_count
61
+ comments_count = comments.not_hidden.count
62
+ update_columns(comments_count: comments_count, updated_at: Time.current)
63
+ end
64
+ # rubocop:enable Rails/SkipsModelValidations
54
65
  end
55
66
  end
56
67
  end
@@ -26,9 +26,13 @@ module Decidim
26
26
  commentable_type = resource.commentable_type
27
27
  commentable_id = resource.id.to_s
28
28
  node_id = "comments-for-#{commentable_type.demodulize}-#{commentable_id}"
29
- react_comments_component(node_id, commentableType: commentable_type,
30
- commentableId: commentable_id,
31
- locale: I18n.locale)
29
+ react_comments_component(
30
+ node_id, commentableType: commentable_type,
31
+ commentableId: commentable_id,
32
+ locale: I18n.locale,
33
+ toggleTranslations: machine_translations_toggled?,
34
+ commentsMaxLength: comments_max_length(resource)
35
+ )
32
36
  end
33
37
 
34
38
  # Private: Render Comments component using inline javascript
@@ -44,11 +48,31 @@ module Decidim
44
48
  {
45
49
  commentableType: "#{props[:commentableType]}",
46
50
  commentableId: "#{props[:commentableId]}",
47
- locale: "#{props[:locale]}"
51
+ locale: "#{props[:locale]}",
52
+ toggleTranslations: #{props[:toggleTranslations]},
53
+ commentsMaxLength: "#{props[:commentsMaxLength]}"
48
54
  }
49
55
  );
50
56
  })
51
57
  end
58
+
59
+ def comments_max_length(resource)
60
+ return 1000 unless resource.respond_to?(:component)
61
+ return component_comments_max_length(resource) if component_comments_max_length(resource)
62
+ return organization_comments_max_length(resource) if organization_comments_max_length(resource)
63
+
64
+ 1000
65
+ end
66
+
67
+ def component_comments_max_length(resource)
68
+ return unless resource.component&.settings.respond_to?(:comments_max_length)
69
+
70
+ resource.component.settings.comments_max_length if resource.component.settings.comments_max_length.positive?
71
+ end
72
+
73
+ def organization_comments_max_length(resource)
74
+ resource.component.organization.comments_max_length if resource.component.organization.comments_max_length.positive?
75
+ end
52
76
  end
53
77
  end
54
78
  end
@@ -59,6 +59,19 @@ module Decidim
59
59
  metric_operation.manager_class = "Decidim::Comments::Metrics::CommentParticipantsMetricMeasure"
60
60
  end
61
61
  end
62
+
63
+ initializer "decidim_comments.register_resources" do
64
+ Decidim.register_resource(:comment) do |resource|
65
+ resource.model_class_name = "Decidim::Comments::Comment"
66
+ resource.card = "decidim/comments/comment"
67
+ resource.searchable = true
68
+ end
69
+ end
70
+
71
+ initializer "decidim_comments.add_cells_view_paths" do
72
+ Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Comments::Engine.root}/app/cells")
73
+ Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Comments::Engine.root}/app/views") # for partials
74
+ end
62
75
  end
63
76
  end
64
77
  end
@@ -16,8 +16,12 @@ module Decidim
16
16
 
17
17
  argument :id, !types.String, "The commentable's ID"
18
18
  argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
19
+ argument :locale, !types.String, "The locale for which to get the comments text"
20
+ argument :toggleTranslations, !types.Boolean, "Whether the user asked to toggle the machine translations or not."
19
21
 
20
22
  resolve lambda { |_obj, args, _ctx|
23
+ I18n.locale = args[:locale].presence
24
+ RequestStore.store[:toggle_machine_translations] = args[:toggleTranslations]
21
25
  args[:type].constantize.find(args[:id])
22
26
  }
23
27
  end
@@ -26,8 +30,12 @@ module Decidim
26
30
  description "A comment"
27
31
 
28
32
  argument :id, !types.ID, "The comment's id"
33
+ argument :locale, !types.String, "The locale for which to get the comments text"
34
+ argument :toggleTranslations, !types.Boolean, "Whether the user asked to toggle the machine translations or not."
29
35
 
30
36
  resolve lambda { |_obj, args, _ctx|
37
+ I18n.locale = args[:locale].presence
38
+ RequestStore.store[:toggle_machine_translations] = args[:toggleTranslations]
31
39
  Comment.find(args["id"])
32
40
  }
33
41
  end
@@ -16,8 +16,12 @@ module Decidim
16
16
 
17
17
  argument :id, !types.String, "The commentable's ID"
18
18
  argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
19
+ argument :locale, !types.String, "The locale for which to get the comments text"
20
+ argument :toggleTranslations, !types.Boolean, "Whether the user asked to toggle the machine translations or not."
19
21
 
20
22
  resolve lambda { |_obj, args, _ctx|
23
+ I18n.locale = args[:locale].presence
24
+ RequestStore.store[:toggle_machine_translations] = args[:toggleTranslations]
21
25
  args[:type].constantize.find(args[:id])
22
26
  }
23
27
  end
@@ -7,7 +7,16 @@ FactoryBot.define do
7
7
  author { build(:user, organization: commentable.organization) }
8
8
  commentable { build(:dummy_resource) }
9
9
  root_commentable { commentable }
10
- body { Faker::Lorem.paragraph }
10
+ body { Decidim::Faker::Localized.paragraph }
11
+
12
+ after(:build) do |comment, evaluator|
13
+ comment.body = if evaluator.body.is_a?(String)
14
+ { comment.root_commentable.organization.default_locale || "en" => evaluator.body }
15
+ else
16
+ evaluator.body
17
+ end
18
+ comment.body = Decidim::ContentProcessor.parse_with_processor(:hashtag, comment.body, current_organization: comment.root_commentable.organization).rewrite
19
+ end
11
20
 
12
21
  trait :comment_on_comment do
13
22
  author { build(:user, organization: root_commentable.organization) }
@@ -16,7 +16,7 @@ shared_context "when it's a comment event" do
16
16
  let(:comment_author_name) { decidim_html_escape comment.author.name }
17
17
 
18
18
  let(:extra) { { comment_id: comment.id } }
19
- let(:resource_title) { decidim_html_escape resource.title }
19
+ let(:resource_title) { decidim_html_escape(translated(resource.title)) }
20
20
  let(:user_group) do
21
21
  user_group = create(:user_group, :verified, organization: organization, users: [comment_author])
22
22
  comment.update!(user_group: user_group)
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-comments version.
5
5
  module Comments
6
6
  def self.version
7
- "0.22.0"
7
+ "0.23.0"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-01 00:00:00.000000000 Z
13
+ date: 2020-11-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-core
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.22.0
21
+ version: 0.23.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.22.0
28
+ version: 0.23.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: jquery-rails
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -60,28 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.22.0
63
+ version: 0.23.0
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.22.0
70
+ version: 0.23.0
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: decidim-dev
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.22.0
77
+ version: 0.23.0
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.22.0
84
+ version: 0.23.0
85
85
  description: Pluggable comments system for some components.
86
86
  email:
87
87
  - josepjaume@gmail.com
@@ -98,6 +98,10 @@ files:
98
98
  - app/assets/javascripts/decidim/comments/bundle.js.map
99
99
  - app/assets/javascripts/decidim/comments/comments.js.erb
100
100
  - app/cells/decidim/comments/comment_activity_cell.rb
101
+ - app/cells/decidim/comments/comment_cell.rb
102
+ - app/cells/decidim/comments/comment_m/footer.erb
103
+ - app/cells/decidim/comments/comment_m/top.erb
104
+ - app/cells/decidim/comments/comment_m_cell.rb
101
105
  - app/commands/decidim/comments/create_comment.rb
102
106
  - app/commands/decidim/comments/vote_comment.rb
103
107
  - app/events/decidim/comments/comment_by_followed_user_event.rb
@@ -151,6 +155,7 @@ files:
151
155
  - app/frontend/support/require_all.ts
152
156
  - app/frontend/support/resolve_graphql_query.ts
153
157
  - app/frontend/support/schema.ts
158
+ - app/helpers/decidim/comments/comment_cells_helper.rb
154
159
  - app/models/decidim/comments/application_record.rb
155
160
  - app/models/decidim/comments/comment.rb
156
161
  - app/models/decidim/comments/comment_vote.rb
@@ -165,22 +170,27 @@ files:
165
170
  - app/types/decidim/comments/commentable_interface.rb
166
171
  - app/types/decidim/comments/commentable_mutation_type.rb
167
172
  - app/types/decidim/comments/commentable_type.rb
173
+ - config/locales/am-ET.yml
168
174
  - config/locales/ar-SA.yml
169
175
  - config/locales/ar.yml
170
176
  - config/locales/bg-BG.yml
177
+ - config/locales/bg.yml
171
178
  - config/locales/ca.yml
172
179
  - config/locales/cs-CZ.yml
173
180
  - config/locales/cs.yml
174
181
  - config/locales/da-DK.yml
182
+ - config/locales/da.yml
175
183
  - config/locales/de.yml
176
184
  - config/locales/el-GR.yml
177
185
  - config/locales/el.yml
178
186
  - config/locales/en.yml
179
187
  - config/locales/eo-UY.yml
188
+ - config/locales/eo.yml
180
189
  - config/locales/es-MX.yml
181
190
  - config/locales/es-PY.yml
182
191
  - config/locales/es.yml
183
192
  - config/locales/et-EE.yml
193
+ - config/locales/et.yml
184
194
  - config/locales/eu.yml
185
195
  - config/locales/fi-pl.yml
186
196
  - config/locales/fi-plain.yml
@@ -190,16 +200,24 @@ files:
190
200
  - config/locales/ga-IE.yml
191
201
  - config/locales/gl.yml
192
202
  - config/locales/hr-HR.yml
203
+ - config/locales/hr.yml
193
204
  - config/locales/hu.yml
194
205
  - config/locales/id-ID.yml
195
206
  - config/locales/is-IS.yml
207
+ - config/locales/is.yml
196
208
  - config/locales/it.yml
197
209
  - config/locales/ja-JP.yml
210
+ - config/locales/ja.yml
211
+ - config/locales/ko-KR.yml
212
+ - config/locales/ko.yml
198
213
  - config/locales/lt-LT.yml
199
- - config/locales/lv-LV.yml
214
+ - config/locales/lt.yml
215
+ - config/locales/lv.yml
200
216
  - config/locales/mt-MT.yml
217
+ - config/locales/mt.yml
201
218
  - config/locales/nl.yml
202
219
  - config/locales/no.yml
220
+ - config/locales/om-ET.yml
203
221
  - config/locales/pl.yml
204
222
  - config/locales/pt-BR.yml
205
223
  - config/locales/pt.yml
@@ -208,10 +226,16 @@ files:
208
226
  - config/locales/sk-SK.yml
209
227
  - config/locales/sk.yml
210
228
  - config/locales/sl.yml
229
+ - config/locales/so-SO.yml
211
230
  - config/locales/sr-CS.yml
212
231
  - config/locales/sv.yml
232
+ - config/locales/ti-ER.yml
213
233
  - config/locales/tr-TR.yml
214
234
  - config/locales/uk.yml
235
+ - config/locales/vi-VN.yml
236
+ - config/locales/vi.yml
237
+ - config/locales/zh-CN.yml
238
+ - config/locales/zh-TW.yml
215
239
  - db/migrate/20161130143508_create_comments.rb
216
240
  - db/migrate/20161214082645_add_depth_to_comments.rb
217
241
  - db/migrate/20161216102820_add_alignment_to_comments.rb
@@ -224,6 +248,8 @@ files:
224
248
  - db/migrate/20181016142511_make_authors_polymorphic_for_comments.rb
225
249
  - db/migrate/20181019092928_make_author_polymorphic_for_comment_votes.rb
226
250
  - db/migrate/20200320105911_index_foreign_keys_in_decidim_comments_comments.rb
251
+ - db/migrate/20200706123136_make_comments_handle_i18n.rb
252
+ - db/migrate/20200828101910_add_commentable_counter_cache_to_comments.rb
227
253
  - db/seeds.rb
228
254
  - lib/decidim/comments.rb
229
255
  - lib/decidim/comments/admin.rb
@@ -257,14 +283,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
283
  requirements:
258
284
  - - ">="
259
285
  - !ruby/object:Gem::Version
260
- version: '2.5'
286
+ version: '2.6'
261
287
  required_rubygems_version: !ruby/object:Gem::Requirement
262
288
  requirements:
263
289
  - - ">="
264
290
  - !ruby/object:Gem::Version
265
291
  version: '0'
266
292
  requirements: []
267
- rubygems_version: 3.1.2
293
+ rubygems_version: 3.0.3
268
294
  signing_key:
269
295
  specification_version: 4
270
296
  summary: Decidim comments module