Skip to content

Instantly share code, notes, and snippets.

@huguesbr

huguesbr/diff.patch

Created May 29, 2018
Embed
What would you like to do?
$ 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