Created
May 29, 2018 08:09
-
-
Save huguesbr/0e97558e00726eba9790cd57eaa70b7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git diff | |
diff --git a/app/services/conversation_service.rb b/app/services/conversation_service.rb | |
index f1dd0faa..f54d3a8d 100644 | |
--- a/app/services/conversation_service.rb | |
+++ b/app/services/conversation_service.rb | |
@@ -164,20 +164,19 @@ class ConversationService | |
send_push_notifications_to_users(recipient, user, conversation, :remove_user) | |
end | |
log_action(conversation, :update_out, removed_memberships.map(&:id)) if removed_memberships.any? | |
+ send_email_notifications(conversation, removed_memberships, :remove) | |
+ | |
# # notify new members in this version | |
# # new_memberships = conversation.conversation_memberships_at_version(conversation.version).where(deleted_at: nil) | |
added_memberships = memberships[:added] | |
- | |
- send_email_notifications(conversation, conversation.conversation_memberships.at_version(conversation.version), action) | |
- | |
added_users = added_memberships.map(&:user).compact | |
- | |
added_users.each do |recipient| | |
send_push_notifications_to_users(recipient, user, conversation, :create) | |
end | |
- | |
# system log | |
log_action(conversation, :update_in, added_memberships.map(&:id)) if added_memberships.any? | |
+ send_email_notifications(conversation, added_memberships, :create) | |
+ | |
# notify existing members | |
existing_users = conversation.users.where.not(id: added_users.map {|u| u.id}) | |
existing_users.each do |recipient| | |
@@ -209,24 +208,9 @@ class ConversationService | |
def send_email_notifications(conversation, memberships, action) | |
sendgrid_service = SendgridMailerService.new(conversation.owner) | |
- members = memberships.pluck(:email, :deleted_at).compact | |
- case action | |
- when action == :create | |
- members.each do |member| | |
- sendgrid_service.send_chail_notification(member.email, :create) | |
- end | |
- when action == :update | |
- members.each do |member| | |
- if member.deleted_at | |
- sendgrid_service.send_chail_notification(member.email, :remove) | |
- else | |
- sendgrid_service.send_chail_notification(member.email, :create) | |
- end | |
- end | |
- when action == :delete | |
- members.each do |member| | |
- sendgrid_service.send_chail_notification(member.email, :delete) | |
- end | |
+ emails = memberships.pluck(:email).compact | |
+ emails.each do |email| | |
+ sendgrid_service.send_chail_notification(email, :create) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment