decidim-comments 0.26.10 → 0.27.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/cells/decidim/comments/comment/actions.erb +0 -5
- data/app/cells/decidim/comments/comment/show.erb +3 -3
- data/app/cells/decidim/comments/comment_cell.rb +2 -2
- data/app/cells/decidim/comments/comments/comments_loading.erb +3 -0
- data/app/cells/decidim/comments/comments/show.erb +1 -0
- data/app/cells/decidim/comments/comments_cell.rb +7 -12
- data/app/cells/decidim/comments/edit_comment_modal_form_cell.rb +1 -1
- data/app/commands/decidim/comments/create_comment.rb +1 -1
- data/app/commands/decidim/comments/delete_comment.rb +1 -1
- data/app/commands/decidim/comments/update_comment.rb +8 -1
- data/app/commands/decidim/comments/vote_comment.rb +1 -1
- data/app/controllers/decidim/comments/comments_controller.rb +9 -11
- data/app/helpers/decidim/comments/comment_cells_helper.rb +1 -1
- data/app/models/decidim/comments/comment.rb +9 -10
- data/app/models/decidim/comments/comment_vote.rb +1 -1
- data/app/packs/src/decidim/comments/comments.component.js +32 -13
- data/app/packs/src/decidim/comments/comments.component.test.js +9 -5
- data/app/permissions/decidim/comments/permissions.rb +5 -7
- data/app/queries/decidim/comments/sorted_comments.rb +1 -3
- data/app/services/decidim/comments/new_comment_notification_creator.rb +1 -1
- data/app/views/decidim/comments/comments/create.js.erb +0 -4
- data/app/views/decidim/comments/comments/index.js.erb +1 -0
- data/app/views/decidim/comments/comments/reload.js.erb +1 -0
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +3 -65
- data/config/locales/bg.yml +1 -0
- data/config/locales/ca.yml +2 -3
- data/config/locales/cs.yml +2 -5
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +4 -5
- data/config/locales/el.yml +3 -13
- data/config/locales/en.yml +1 -3
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +2 -3
- data/config/locales/es-PY.yml +2 -3
- data/config/locales/es.yml +2 -3
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +35 -41
- data/config/locales/fi-plain.yml +2 -3
- data/config/locales/fi.yml +2 -3
- data/config/locales/fr-CA.yml +4 -5
- data/config/locales/fr.yml +4 -5
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +2 -0
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +3 -56
- data/config/locales/id-ID.yml +2 -1
- data/config/locales/is-IS.yml +3 -1
- data/config/locales/it.yml +2 -0
- data/config/locales/ja.yml +6 -6
- data/config/locales/ko.yml +1 -0
- data/config/locales/lb.yml +3 -1
- data/config/locales/lt.yml +1 -179
- data/config/locales/lv.yml +3 -1
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +2 -18
- data/config/locales/no.yml +2 -0
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +2 -13
- data/config/locales/pt-BR.yml +3 -3
- data/config/locales/pt.yml +2 -0
- data/config/locales/ro-RO.yml +2 -6
- data/config/locales/ru.yml +2 -1
- data/config/locales/si-LK.yml +4 -0
- data/config/locales/sk.yml +3 -1
- data/config/locales/sl.yml +1 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +2 -0
- data/config/locales/sv.yml +2 -5
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +3 -0
- data/config/locales/uk.yml +2 -0
- data/config/locales/val-ES.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +3 -1
- data/config/locales/zh-TW.yml +1 -167
- data/db/migrate/20181016142511_make_authors_polymorphic_for_comments.rb +1 -0
- data/db/migrate/20181019092928_make_author_polymorphic_for_comment_votes.rb +1 -0
- data/lib/decidim/comments/comment_serializer.rb +1 -1
- data/lib/decidim/comments/comment_vote_serializer.rb +1 -1
- data/lib/decidim/comments/export.rb +0 -2
- data/lib/decidim/comments/markdown.rb +0 -12
- data/lib/decidim/comments/test/shared_examples/translatable_comment.rb +1 -1
- data/lib/decidim/comments/version.rb +1 -1
- metadata +13 -21
- data/config/environment.rb +0 -3
- data/config/locales/fa-IR.yml +0 -1
- data/config/locales/gn-PY.yml +0 -1
- data/config/locales/ka-GE.yml +0 -1
- data/config/locales/kaa.yml +0 -1
- data/config/locales/lo-LA.yml +0 -1
- data/config/locales/oc-FR.yml +0 -1
- data/config/locales/sq-AL.yml +0 -1
- data/config/locales/th-TH.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15e0e5dd8fbb2fc7171061fa36077e83f956f3ada42b41dfa32cd8e8f60cdd0a
|
4
|
+
data.tar.gz: 6cb4e67d56972f657983cc174806b8766d0916fb55b7ca783ee2e8a684859283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a7482658e91430342214a3d668979c0450b1203c28725ab083c46773b6c39474f148a4489238c90187cda2407a81edbc1c7a1b9bd26944081ce36261f86e7e
|
7
|
+
data.tar.gz: ee42d7e4922a5cbc826a1a98f73b1d1056d4ce6879a398da32ad6962d9987323f7b37b2e1fc57111251baf2185301cbdc0e370621107778afd2fb47263dc285b
|
@@ -1,9 +1,4 @@
|
|
1
1
|
<div class="comment__actions">
|
2
|
-
<button class="comment__hide muted-link <%= depth.zero? && has_replies_in_children? ? "" : "hide" %>" aria-controls="comment-<%= model.id %>-replies" data-toggle="comment_<%= model.id %>">
|
3
|
-
<%= icon "comment-square", class: "icon--small", role: "img", "aria-hidden": true %>
|
4
|
-
<span class="hide-comment-replies"><%= t("decidim.components.comment.hide_replies") %></span>
|
5
|
-
<span class="show-comment-replies"><%= t("decidim.components.comment.show_replies", count: replies.size, replies_count: replies.size ) %></span>
|
6
|
-
</button>
|
7
2
|
<% if can_reply? %>
|
8
3
|
<button class="comment__reply muted-link" aria-controls="<%= reply_id %>" data-toggle="<%= reply_id %>">
|
9
4
|
<%= icon "pencil", class: "icon--small", role: "img", "aria-hidden": true %> <%= t("decidim.components.comment.reply") %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= content_tag :div, id: "comment_#{model.id}", class: comment_classes, data: {
|
1
|
+
<%= content_tag :div, id: "comment_#{model.id}", class: comment_classes, data: { comment_id: model.id } do %>
|
2
2
|
<% if model.hidden? %>
|
3
3
|
<%= render :moderation_data %>
|
4
4
|
<% elsif model.deleted? %>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<%= votes %>
|
32
32
|
</div>
|
33
33
|
<% end %>
|
34
|
-
<div id="comment-<%= model.id %>-replies"
|
34
|
+
<div id="comment-<%= model.id %>-replies">
|
35
35
|
<% if has_replies_in_children? %>
|
36
36
|
<% replies.each do |reply| %>
|
37
37
|
<%= cell("decidim/comments/comment", reply, root_depth: root_depth, order: order, reloaded: reloaded?) %>
|
@@ -39,7 +39,7 @@
|
|
39
39
|
<% end %>
|
40
40
|
</div>
|
41
41
|
<% if can_reply? %>
|
42
|
-
<div class="comment__additionalreply<%= " hide" unless commentable? %>
|
42
|
+
<div class="comment__additionalreply<%= " hide" unless commentable? %>">
|
43
43
|
<button class="comment__reply muted-link" aria-controls="<%= reply_id %>" data-toggle="<%= reply_id %>">
|
44
44
|
<%= icon "pencil", class: "icon--small", role: "img", "aria-hidden": true %> <%= t("decidim.components.comment.reply") %>
|
45
45
|
</button>
|
@@ -186,11 +186,11 @@ module Decidim
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def has_replies?
|
189
|
-
model.comment_threads.
|
189
|
+
model.comment_threads.not_hidden.not_deleted.exists?
|
190
190
|
end
|
191
191
|
|
192
192
|
def has_replies_in_children?
|
193
|
-
|
193
|
+
model.descendants.where(decidim_commentable_type: "Decidim::Comments::Comment").not_hidden.not_deleted.exists?
|
194
194
|
end
|
195
195
|
|
196
196
|
# action_authorization_button expects current_component to be available
|
@@ -22,6 +22,12 @@ module Decidim
|
|
22
22
|
render :single_comment_warning
|
23
23
|
end
|
24
24
|
|
25
|
+
def comments_loading
|
26
|
+
return if single_comment?
|
27
|
+
|
28
|
+
render :comments_loading
|
29
|
+
end
|
30
|
+
|
25
31
|
def blocked_comments_warning
|
26
32
|
return unless comments_blocked?
|
27
33
|
return unless user_comments_blocked?
|
@@ -43,11 +49,7 @@ module Decidim
|
|
43
49
|
end
|
44
50
|
|
45
51
|
def comments
|
46
|
-
|
47
|
-
[single_comment]
|
48
|
-
else
|
49
|
-
SortedComments.for(model, order_by: order)
|
50
|
-
end
|
52
|
+
single_comment? ? [single_comment] : []
|
51
53
|
end
|
52
54
|
|
53
55
|
def comments_count
|
@@ -97,17 +99,10 @@ module Decidim
|
|
97
99
|
commentableGid: model.to_signed_global_id.to_s,
|
98
100
|
commentsUrl: decidim_comments.comments_path,
|
99
101
|
rootDepth: root_depth,
|
100
|
-
lastCommentId: last_comment_id,
|
101
102
|
order: order
|
102
103
|
}
|
103
104
|
end
|
104
105
|
|
105
|
-
def last_comment_id
|
106
|
-
Decidim::Comments::Comment.where(
|
107
|
-
root_commentable: model
|
108
|
-
).order(:id).pluck(:id).last
|
109
|
-
end
|
110
|
-
|
111
106
|
def single_comment?
|
112
107
|
single_comment.present?
|
113
108
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Comments
|
5
|
-
# A cell to display a form for
|
5
|
+
# A cell to display a form for edditing a comment.
|
6
6
|
class EditCommentModalFormCell < Decidim::ViewModel
|
7
7
|
delegate :current_user, :user_signed_in?, to: :controller
|
8
8
|
alias comment model
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Comments
|
5
5
|
# A command with all the business logic to update an existing comment
|
6
|
-
class UpdateComment <
|
6
|
+
class UpdateComment < Decidim::Command
|
7
7
|
# Public: Initializes the command.
|
8
8
|
#
|
9
9
|
# comment - Decidim::Comments::Comment
|
@@ -48,7 +48,14 @@ module Decidim
|
|
48
48
|
edit: true
|
49
49
|
)
|
50
50
|
|
51
|
+
mentioned_users = parsed.metadata[:user].users
|
52
|
+
mentioned_groups = parsed.metadata[:user_group].groups
|
51
53
|
CommentCreation.publish(@comment, parsed.metadata)
|
54
|
+
send_notifications(mentioned_users, mentioned_groups)
|
55
|
+
end
|
56
|
+
|
57
|
+
def send_notifications(mentioned_users, mentioned_groups)
|
58
|
+
NewCommentNotificationCreator.new(comment, mentioned_users, mentioned_groups).create
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
@@ -13,7 +13,7 @@ module Decidim
|
|
13
13
|
before_action :set_commentable, except: [:destroy, :update]
|
14
14
|
before_action :ensure_commentable!, except: [:destroy, :update]
|
15
15
|
|
16
|
-
helper_method :root_depth, :commentable, :order, :reply?, :reload
|
16
|
+
helper_method :root_depth, :commentable, :order, :reply?, :reload?
|
17
17
|
|
18
18
|
def index
|
19
19
|
enforce_permission_to :read, :comment, commentable: commentable
|
@@ -23,6 +23,12 @@ module Decidim
|
|
23
23
|
order_by: order,
|
24
24
|
after: params.fetch(:after, 0).to_i
|
25
25
|
)
|
26
|
+
@comments = @comments.reject do |comment|
|
27
|
+
next if comment.depth < 1
|
28
|
+
next if !comment.deleted? && !comment.hidden?
|
29
|
+
|
30
|
+
comment.commentable.descendants.where(decidim_commentable_type: "Decidim::Comments::Comment").not_hidden.not_deleted.blank?
|
31
|
+
end
|
26
32
|
@comments_count = commentable.comments_count
|
27
33
|
|
28
34
|
respond_to do |format|
|
@@ -135,7 +141,7 @@ module Decidim
|
|
135
141
|
end
|
136
142
|
|
137
143
|
def handle_success(comment)
|
138
|
-
@comment = comment
|
144
|
+
@comment = comment
|
139
145
|
@comments_count = case commentable
|
140
146
|
when Decidim::Comments::Comment
|
141
147
|
commentable.root_commentable.comments_count
|
@@ -144,14 +150,6 @@ module Decidim
|
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
147
|
-
def root_comment
|
148
|
-
@root_comment ||= begin
|
149
|
-
root_comment = comment
|
150
|
-
root_comment = root_comment.commentable while root_comment.commentable.is_a?(Decidim::Comments::Comment)
|
151
|
-
root_comment
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
153
|
def commentable_gid
|
156
154
|
case action_name
|
157
155
|
when "create"
|
@@ -178,7 +176,7 @@ module Decidim
|
|
178
176
|
end
|
179
177
|
|
180
178
|
def commentable_path
|
181
|
-
return commentable.polymorphic_resource_path({}) if commentable
|
179
|
+
return commentable.polymorphic_resource_path({}) if commentable.respond_to?(:polymorphic_resource_path)
|
182
180
|
|
183
181
|
resource_locator(commentable).path
|
184
182
|
end
|
@@ -14,7 +14,7 @@ module Decidim
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def resource_link_path
|
17
|
-
return root_commentable.polymorphic_resource_path(url_params) if root_commentable
|
17
|
+
return root_commentable.polymorphic_resource_path(url_params) if root_commentable.respond_to?(:polymorphic_resource_path)
|
18
18
|
|
19
19
|
resource_locator(root_commentable).path(url_params)
|
20
20
|
end
|
@@ -10,12 +10,13 @@ module Decidim
|
|
10
10
|
include Decidim::Authorable
|
11
11
|
include Decidim::Comments::Commentable
|
12
12
|
include Decidim::FriendlyDates
|
13
|
-
include Decidim::
|
13
|
+
include Decidim::DownloadYourData
|
14
14
|
include Decidim::Traceable
|
15
15
|
include Decidim::Loggable
|
16
16
|
include Decidim::Searchable
|
17
17
|
include Decidim::TranslatableResource
|
18
18
|
include Decidim::TranslatableAttributes
|
19
|
+
include Decidim::ActsAsTree
|
19
20
|
|
20
21
|
# Limit the max depth of a comment tree. If C is a comment and R is a reply:
|
21
22
|
# C (depth 0)
|
@@ -27,6 +28,8 @@ module Decidim
|
|
27
28
|
|
28
29
|
translatable_fields :body
|
29
30
|
|
31
|
+
parent_item_foreign_key :decidim_commentable_id
|
32
|
+
|
30
33
|
belongs_to :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", polymorphic: true
|
31
34
|
belongs_to :root_commentable, foreign_key: "decidim_root_commentable_id", foreign_type: "decidim_root_commentable_type", polymorphic: true, touch: true
|
32
35
|
belongs_to :participatory_space, foreign_key: "decidim_participatory_space_id", foreign_type: "decidim_participatory_space_type", polymorphic: true, optional: true
|
@@ -53,6 +56,8 @@ module Decidim
|
|
53
56
|
validate :body_length
|
54
57
|
validate :commentable_can_have_comments
|
55
58
|
|
59
|
+
delegate :organization, to: :commentable
|
60
|
+
|
56
61
|
scope :not_deleted, -> { where(deleted_at: nil) }
|
57
62
|
|
58
63
|
translatable_fields :body
|
@@ -76,10 +81,6 @@ module Decidim
|
|
76
81
|
where(alignment: -1)
|
77
82
|
end
|
78
83
|
|
79
|
-
def organization
|
80
|
-
commentable&.organization || participatory_space&.organization
|
81
|
-
end
|
82
|
-
|
83
84
|
def visible?
|
84
85
|
participatory_space.try(:visible?) && component.try(:published?)
|
85
86
|
end
|
@@ -130,11 +131,9 @@ module Decidim
|
|
130
131
|
|
131
132
|
# Public: Overrides the `reported_content_url` Reportable concern method.
|
132
133
|
def reported_content_url
|
133
|
-
return unless root_commentable
|
134
|
-
|
135
134
|
url_params = { anchor: "comment_#{id}" }
|
136
135
|
|
137
|
-
if root_commentable
|
136
|
+
if root_commentable.respond_to?(:polymorphic_resource_url)
|
138
137
|
root_commentable.polymorphic_resource_url(url_params)
|
139
138
|
else
|
140
139
|
ResourceLocatorPresenter.new(root_commentable).url(url_params)
|
@@ -159,7 +158,7 @@ module Decidim
|
|
159
158
|
# Expects all +resources+ to be of the same "commentable_type".
|
160
159
|
# If the result is not `Decidim::Comments::Commentable` returns `nil`.
|
161
160
|
def self.user_commentators_ids_in(resources)
|
162
|
-
if resources.first
|
161
|
+
if resources.first.is_a?(Decidim::Comments::Commentable)
|
163
162
|
commentable_type = resources.first.class.name
|
164
163
|
Decidim::Comments::Comment.select("DISTINCT decidim_author_id").not_hidden.not_deleted
|
165
164
|
.where(decidim_commentable_id: resources.pluck(:id))
|
@@ -171,7 +170,7 @@ module Decidim
|
|
171
170
|
end
|
172
171
|
|
173
172
|
def can_participate?(user)
|
174
|
-
return true unless root_commentable
|
173
|
+
return true unless root_commentable.respond_to?(:can_participate?)
|
175
174
|
|
176
175
|
root_commentable.can_participate?(user)
|
177
176
|
end
|
@@ -5,7 +5,7 @@ module Decidim
|
|
5
5
|
# A comment can include user votes. A user should be able to upVote, votes with
|
6
6
|
# weight 1 and downVote, votes with weight -1.
|
7
7
|
class CommentVote < ApplicationRecord
|
8
|
-
include Decidim::
|
8
|
+
include Decidim::DownloadYourData
|
9
9
|
|
10
10
|
belongs_to :comment, foreign_key: "decidim_comment_id", class_name: "Comment"
|
11
11
|
belongs_to :author, foreign_key: "decidim_author_id", foreign_type: "decidim_author_type", polymorphic: true
|
@@ -1,4 +1,6 @@
|
|
1
1
|
/* eslint id-length: ["error", { "exceptions": ["$"] }] */
|
2
|
+
/* eslint max-lines: ["error", {"max": 350, "skipBlankLines": true}] */
|
3
|
+
|
2
4
|
|
3
5
|
/**
|
4
6
|
* A plain Javascript component that handles the comments.
|
@@ -10,6 +12,8 @@
|
|
10
12
|
// This is necessary for testing purposes
|
11
13
|
const $ = window.$;
|
12
14
|
|
15
|
+
import Rails from "@rails/ujs";
|
16
|
+
|
13
17
|
import { createCharacterCounter } from "src/decidim/input_character_counter"
|
14
18
|
import ExternalLink from "src/decidim/external_link"
|
15
19
|
import updateExternalDomainLinks from "src/decidim/external_domain_warning"
|
@@ -23,6 +27,8 @@ export default class CommentsComponent {
|
|
23
27
|
this.order = config.order;
|
24
28
|
this.lastCommentId = config.lastCommentId;
|
25
29
|
this.pollingInterval = config.pollingInterval || 15000;
|
30
|
+
this.singleComment = config.singleComment;
|
31
|
+
this.toggleTranslations = config.toggleTranslations;
|
26
32
|
this.id = this.$element.attr("id") || this._getUID();
|
27
33
|
this.mounted = false;
|
28
34
|
}
|
@@ -36,6 +42,9 @@ export default class CommentsComponent {
|
|
36
42
|
if (this.$element.length > 0 && !this.mounted) {
|
37
43
|
this.mounted = true;
|
38
44
|
this._initializeComments(this.$element);
|
45
|
+
if (!this.singleComment) {
|
46
|
+
this._fetchComments();
|
47
|
+
}
|
39
48
|
|
40
49
|
$(".order-by__dropdown .is-submenu-item a", this.$element).on("click.decidim-comments", () => this._onInitOrder());
|
41
50
|
}
|
@@ -133,8 +142,6 @@ export default class CommentsComponent {
|
|
133
142
|
$text.get(0).addEventListener("emoji.added", this._onTextInput);
|
134
143
|
}
|
135
144
|
});
|
136
|
-
|
137
|
-
this._pollComments();
|
138
145
|
}
|
139
146
|
|
140
147
|
/**
|
@@ -200,20 +207,32 @@ export default class CommentsComponent {
|
|
200
207
|
this._stopPolling();
|
201
208
|
|
202
209
|
this.pollTimeout = setTimeout(() => {
|
203
|
-
|
204
|
-
url: this.commentsUrl,
|
205
|
-
type: "GET",
|
206
|
-
data: new URLSearchParams({
|
207
|
-
"commentable_gid": this.commentableGid,
|
208
|
-
"root_depth": this.rootDepth,
|
209
|
-
"order": this.order,
|
210
|
-
"after": this.lastCommentId
|
211
|
-
}),
|
212
|
-
success: this._pollComments()
|
213
|
-
})
|
210
|
+
this._fetchComments();
|
214
211
|
}, this.pollingInterval);
|
215
212
|
}
|
216
213
|
|
214
|
+
/**
|
215
|
+
* Sends an ajax request based on current
|
216
|
+
* params to get comments for the component
|
217
|
+
* @private
|
218
|
+
* @returns {Void} - Returns nothing
|
219
|
+
*/
|
220
|
+
_fetchComments() {
|
221
|
+
Rails.ajax({
|
222
|
+
url: this.commentsUrl,
|
223
|
+
type: "GET",
|
224
|
+
data: new URLSearchParams({
|
225
|
+
"commentable_gid": this.commentableGid,
|
226
|
+
"root_depth": this.rootDepth,
|
227
|
+
"order": this.order,
|
228
|
+
"after": this.lastCommentId,
|
229
|
+
...(this.toggleTranslations && { "toggle_translations": this.toggleTranslations }),
|
230
|
+
...(this.lastCommentId && { "after": this.lastCommentId })
|
231
|
+
}),
|
232
|
+
success: this._pollComments()
|
233
|
+
})
|
234
|
+
}
|
235
|
+
|
217
236
|
/**
|
218
237
|
* Stops polling for new comments.
|
219
238
|
* @private
|
@@ -13,6 +13,10 @@ window.$.ajax = jest.fn().mockImplementation((...args) => $.ajax(...args));
|
|
13
13
|
import Quill from "quill"
|
14
14
|
window.Quill = Quill
|
15
15
|
|
16
|
+
// Rails.ajax is used by the fetching/polling of the comments
|
17
|
+
import Rails from "@rails/ujs";
|
18
|
+
jest.mock("@rails/ujs");
|
19
|
+
|
16
20
|
// Fake timers for testing polling
|
17
21
|
jest.useFakeTimers();
|
18
22
|
|
@@ -383,16 +387,16 @@ describe("CommentsComponent", () => {
|
|
383
387
|
|
384
388
|
jest.advanceTimersByTime(1000);
|
385
389
|
|
386
|
-
expect(
|
390
|
+
expect(Rails.ajax).toHaveBeenCalledWith({
|
387
391
|
url: "/comments",
|
388
|
-
|
389
|
-
|
390
|
-
data: {
|
392
|
+
type: "GET",
|
393
|
+
data: new URLSearchParams({
|
391
394
|
"commentable_gid": "commentable-gid",
|
392
395
|
"root_depth": 0,
|
393
396
|
order: "older",
|
394
397
|
after: 456
|
395
|
-
}
|
398
|
+
}),
|
399
|
+
success: window.undefined
|
396
400
|
});
|
397
401
|
});
|
398
402
|
|
@@ -51,13 +51,11 @@ module Decidim
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def commentable
|
54
|
-
@commentable ||=
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
54
|
+
@commentable ||= if comment
|
55
|
+
comment.root_commentable
|
56
|
+
else
|
57
|
+
context.fetch(:commentable, nil)
|
58
|
+
end
|
61
59
|
end
|
62
60
|
|
63
61
|
def comment
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Comments
|
5
5
|
# A class used to find comments for a commentable resource
|
6
|
-
class SortedComments <
|
6
|
+
class SortedComments < Decidim::Query
|
7
7
|
attr_reader :commentable
|
8
8
|
|
9
9
|
# Syntactic sugar to initialize the class and return the queried objects.
|
@@ -34,8 +34,6 @@ module Decidim
|
|
34
34
|
.includes(:author, :user_group, :up_votes, :down_votes)
|
35
35
|
|
36
36
|
case @options[:order_by]
|
37
|
-
when "older"
|
38
|
-
order_by_older(scope)
|
39
37
|
when "recent"
|
40
38
|
order_by_recent(scope)
|
41
39
|
when "best_rated"
|
@@ -7,10 +7,6 @@
|
|
7
7
|
var component = $comments.data("comments");
|
8
8
|
if (inReplyTo) {
|
9
9
|
component.addReply(inReplyTo, commentHtml, true);
|
10
|
-
|
11
|
-
var hideButton = $("#comment_" + <%= root_comment.id %>).find(".comment__hide").first();
|
12
|
-
hideButton.find(".show-comment-replies").first().html('<%= t("decidim.components.comment.show_replies", count: Decidim::Comments::SortedComments.for(root_comment.reload).size) %>');
|
13
|
-
hideButton.removeClass("hide");
|
14
10
|
} else {
|
15
11
|
component.addThread(commentHtml, true);
|
16
12
|
}
|
@@ -4,6 +4,7 @@
|
|
4
4
|
var $comments = $("#" + rootCommentableId);
|
5
5
|
var component = $comments.data("comments");
|
6
6
|
|
7
|
+
$(".loading-comments").addClass("hide");
|
7
8
|
<% @comments.each do |comment| %>
|
8
9
|
var commentId = <%= comment.id.to_json %>;
|
9
10
|
var commentHtml = '<%== j(render comment).strip %>';
|
data/config/locales/am-ET.yml
CHANGED