decidim-comments 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/comments/bundle.js +30 -30
  3. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  4. data/app/commands/decidim/comments/create_comment.rb +10 -14
  5. data/app/frontend/application/application.component.tsx +1 -1
  6. data/app/frontend/comments/add_comment_form.component.test.tsx +33 -26
  7. data/app/frontend/comments/add_comment_form.component.tsx +109 -83
  8. data/app/frontend/comments/comment.component.test.tsx +29 -24
  9. data/app/frontend/comments/comment.component.tsx +12 -5
  10. data/app/frontend/comments/comment_thread.component.test.tsx +12 -7
  11. data/app/frontend/comments/comment_thread.component.tsx +7 -2
  12. data/app/frontend/comments/comments.component.tsx +26 -15
  13. data/app/frontend/comments/down_vote_button.component.test.tsx +9 -4
  14. data/app/frontend/comments/down_vote_button.component.tsx +56 -37
  15. data/app/frontend/comments/up_vote_button.component.test.tsx +9 -4
  16. data/app/frontend/comments/up_vote_button.component.tsx +31 -16
  17. data/app/frontend/comments/vote_button.component.tsx +3 -0
  18. data/app/mailers/decidim/comments/comment_notification_mailer.rb +8 -6
  19. data/app/models/decidim/comments/comment.rb +13 -1
  20. data/app/views/decidim/comments/comment_notification_mailer/comment_created.html.erb +1 -1
  21. data/app/views/decidim/comments/comment_notification_mailer/reply_created.html.erb +1 -1
  22. data/config/locales/ca.yml +2 -0
  23. data/config/locales/en.yml +2 -0
  24. data/config/locales/es.yml +2 -0
  25. data/config/locales/fr.yml +2 -2
  26. data/lib/decidim/comments/commentable.rb +1 -0
  27. metadata +6 -6
@@ -1,9 +1,10 @@
1
1
  import * as React from "react";
2
- import { graphql } from "react-apollo";
2
+ import { graphql, MutationFunc } from "react-apollo";
3
3
 
4
4
  import VoteButton from "./vote_button.component";
5
5
 
6
6
  import {
7
+ AddCommentFormCommentableFragment,
7
8
  AddCommentFormSessionFragment,
8
9
  CommentFragment,
9
10
  GetCommentsQuery,
@@ -17,6 +18,8 @@ interface UpVoteButtonProps {
17
18
  } | null;
18
19
  comment: UpVoteButtonFragment;
19
20
  upVote?: () => void;
21
+ rootCommentable: AddCommentFormCommentableFragment;
22
+ orderBy: string;
20
23
  }
21
24
 
22
25
  export const UpVoteButton: React.SFC<UpVoteButtonProps> = ({
@@ -49,9 +52,10 @@ export const UpVoteButton: React.SFC<UpVoteButtonProps> = ({
49
52
  };
50
53
 
51
54
  const upVoteMutation = require("../mutations/up_vote.mutation.graphql");
55
+ const getCommentsQuery = require("../queries/comments.query.graphql");
52
56
 
53
57
  const UpVoteButtonWithMutation = graphql(upVoteMutation, {
54
- props: ({ ownProps, mutate }) => ({
58
+ props: ({ ownProps, mutate }: { ownProps: UpVoteButtonProps, mutate: MutationFunc<UpVoteMutation> }) => ({
55
59
  upVote: () => mutate({
56
60
  variables: {
57
61
  id: ownProps.comment.id,
@@ -68,28 +72,39 @@ const UpVoteButtonWithMutation = graphql(upVoteMutation, {
68
72
  },
69
73
  },
70
74
  },
71
- updateQueries: {
72
- GetComments: (prev: GetCommentsQuery, { mutationResult: { data } }: { mutationResult: { data: UpVoteMutation}}) => {
73
- const commentReducer = (comment: CommentFragment): CommentFragment => {
74
- const replies = comment.comments || [];
75
+ update: (store, result: UpVoteMutation) => {
76
+ const variables = {
77
+ commentableId: ownProps.rootCommentable.id,
78
+ commentableType: ownProps.rootCommentable.type,
79
+ orderBy: ownProps.orderBy,
80
+ };
75
81
 
76
- if (comment.id === ownProps.comment.id && data.comment) {
77
- return data.comment.upVote;
78
- }
79
- return {
80
- ...comment,
81
- comments: replies.map(commentReducer),
82
- };
83
- };
82
+ const commentReducer = (comment: CommentFragment): CommentFragment => {
83
+ const replies = comment.comments || [];
84
+
85
+ if (comment.id === ownProps.comment.id && result.comment) {
86
+ return result.comment.upVote;
87
+ }
84
88
 
85
89
  return {
90
+ ...comment,
91
+ comments: replies.map(commentReducer),
92
+ };
93
+ };
94
+
95
+ const prev = store.readQuery<GetCommentsQuery>({ query: getCommentsQuery, variables });
96
+
97
+ store.writeQuery({
98
+ query: getCommentsQuery,
99
+ data: {
86
100
  ...prev,
87
101
  commentable: {
88
102
  ...prev.commentable,
89
103
  comments: prev.commentable.comments.map(commentReducer),
90
104
  },
91
- };
92
- },
105
+ },
106
+ variables,
107
+ });
93
108
  },
94
109
  }),
95
110
  }),
@@ -36,6 +36,9 @@ const VoteButton: React.SFC<VoteButtonProps> = ({
36
36
  );
37
37
 
38
38
  VoteButton.defaultProps = {
39
+ buttonClassName: "",
40
+ iconName: "",
41
+ votes: 0,
39
42
  selectedClass: "selected",
40
43
  disabled: false,
41
44
  };
@@ -9,26 +9,28 @@ module Decidim
9
9
 
10
10
  helper_method :commentable_title
11
11
 
12
- def comment_created(comment, commentable)
13
- with_user(commentable.author) do
12
+ def comment_created(user, comment, commentable)
13
+ with_user(user) do
14
+ @user = user
14
15
  @comment = comment
15
16
  @commentable = commentable
16
17
  @locator = Decidim::ResourceLocatorPresenter.new(@commentable)
17
18
  @organization = commentable.organization
18
19
  subject = I18n.t("comment_created.subject", scope: "decidim.comments.mailer.comment_notification")
19
- mail(to: commentable.author.email, subject: subject)
20
+ mail(to: user.email, subject: subject)
20
21
  end
21
22
  end
22
23
 
23
- def reply_created(reply, comment, commentable)
24
- with_user(comment.author) do
24
+ def reply_created(user, reply, comment, commentable)
25
+ with_user(user) do
26
+ @user = user
25
27
  @reply = reply
26
28
  @comment = comment
27
29
  @commentable = commentable
28
30
  @locator = Decidim::ResourceLocatorPresenter.new(@commentable)
29
31
  @organization = commentable.organization
30
32
  subject = I18n.t("reply_created.subject", scope: "decidim.comments.mailer.comment_notification")
31
- mail(to: comment.author.email, subject: subject)
33
+ mail(to: user.email, subject: subject)
32
34
  end
33
35
  end
34
36
 
@@ -6,7 +6,7 @@ module Decidim
6
6
  # comment on them. The will be able to create conversations between users
7
7
  # to discuss or share their thoughts about the resource.
8
8
  class Comment < ApplicationRecord
9
- include Reportable
9
+ include Decidim::Reportable
10
10
  include Decidim::Authorable
11
11
  include Decidim::Comments::Commentable
12
12
 
@@ -59,6 +59,18 @@ module Decidim
59
59
  ResourceLocatorPresenter.new(root_commentable).url(anchor: "comment_#{id}")
60
60
  end
61
61
 
62
+ # Public: Overrides the `notifiable?` Notifiable concern method.
63
+ # When a comment is commented the comment's author is notified if it is not the same
64
+ # who has replied the comment and if the comment's author has replied notifiations enabled.
65
+ def notifiable?(context)
66
+ context[:author] != author && author.replies_notifications?
67
+ end
68
+
69
+ # Public: Overrides the `users_to_notify` Notifiable concern method.
70
+ def users_to_notify
71
+ [author]
72
+ end
73
+
62
74
  private
63
75
 
64
76
  # Private: Check if commentable can have comments and if not adds
@@ -1,4 +1,4 @@
1
- <p><%= t("decidim.comments.comment_notification_mailer.hello", name: @commentable.author.name) %></p>
1
+ <p><%= t("decidim.comments.comment_notification_mailer.hello", name: @user.name) %></p>
2
2
 
3
3
  <p>
4
4
  <%=
@@ -1,4 +1,4 @@
1
- <p><%= t("decidim.comments.comment_notification_mailer.hello", name: @comment.author.name) %></p>
1
+ <p><%= t("decidim.comments.comment_notification_mailer.hello", name: @user.name) %></p>
2
2
 
3
3
  <p>
4
4
  <%=
@@ -35,6 +35,8 @@ ca:
35
35
  label: Comentar com a
36
36
  opinion:
37
37
  neutral: Neutral
38
+ remaining_characters: "Queden %{count} caràcters"
39
+ remaining_characters_1: "Queda %{count} caràcter"
38
40
  title: Deixa el teu comentari
39
41
  comment:
40
42
  alignment:
@@ -36,6 +36,8 @@ en:
36
36
  label: Comment as
37
37
  opinion:
38
38
  neutral: Neutral
39
+ remaining_characters: "%{count} characters left"
40
+ remaining_characters_1: "%{count} character left"
39
41
  title: Add your comment
40
42
  comment:
41
43
  alignment:
@@ -35,6 +35,8 @@ es:
35
35
  label: Comentar como
36
36
  opinion:
37
37
  neutral: Neutral
38
+ remaining_characters: "Quedan %{count} caracteres"
39
+ remaining_characters_1: "Queda %{count} carácter"
38
40
  title: Deje su comentario
39
41
  comment:
40
42
  alignment:
@@ -27,7 +27,7 @@ fr:
27
27
  label: Commentaire
28
28
  placeholder: Que pensez-vous de cela?
29
29
  form_error: Le texte est requis et ne peut pas dépasser %{length} caractères.
30
- submit: Envoyer
30
+ submit: Publier
31
31
  user_group_id:
32
32
  label: Commenter en tant que
33
33
  opinion:
@@ -46,7 +46,7 @@ fr:
46
46
  details: Commentaires additionnels
47
47
  reasons:
48
48
  does_not_belong: Contient des activités illégales, des menaces suicidaires, des informations personnelles, ou autre chose que vous pensez ne pas être approprié à %{organization_name}.
49
- offensive: Contient des propos racisme, sexiste, des insultes, des attaques personnelles, des menaces de mort, des incitations au suicide ou toute forme de discours de haine.
49
+ offensive: Contient des propos racistes, sexistes, des insultes, des attaques personnelles, des menaces de mort, des incitations au suicide ou toute forme de discours de haine.
50
50
  spam: Contient des piège-à-clic (clickbait), des publicités, des escroqueries ou des robots fonctionnant au script (script bots).
51
51
  title: Signaler un problème
52
52
  comment_order_selector:
@@ -7,6 +7,7 @@ module Decidim
7
7
  # Shared behaviour for commentable models.
8
8
  module Commentable
9
9
  extend ActiveSupport::Concern
10
+ include Decidim::Notifiable
10
11
 
11
12
  included do
12
13
  has_many :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment"
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.3.2
4
+ version: 0.4.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: 2017-06-19 00:00:00.000000000 Z
13
+ date: 2017-07-12 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.3.2
21
+ version: 0.4.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.3.2
28
+ version: 0.4.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rails
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +60,14 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.3.2
63
+ version: 0.4.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.3.2
70
+ version: 0.4.0
71
71
  description: Pluggable comments system for some components.
72
72
  email:
73
73
  - josepjaume@gmail.com