Skip to content

Commit

Permalink
Don't set To field instead of setting it to Undisclosed Recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
Dantemss committed Oct 23, 2017
1 parent 916a28c commit 08d91e8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 122 deletions.
60 changes: 23 additions & 37 deletions app/mailers/commontator/subscriptions_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ class SubscriptionsMailer < ActionMailer::Base
def comment_created(comment, recipients)
setup_variables(comment, recipients)

mail(to: @to,
bcc: @bcc,
from: @from,
subject: t('commontator.email.comment_created.subject',
creator_name: @creator_name,
commontable_name: @commontable_name,
comment_url: @comment_url)).tap do |message|
message.mailgun_recipient_variables = mailgun_recipient_variables(recipients) \
if uses_mailgun?
mail(@mail_params).tap do |message|
message.mailgun_recipient_variables = @mailgun_recipient_variables if @using_mailgun
end
end

Expand All @@ -22,42 +15,35 @@ def setup_variables(comment, recipients)
@thread = @comment.thread
@creator = @comment.creator

@creator_name = Commontator.commontator_name(@creator)

@commontable_name = Commontator.commontable_name(@thread)
@mail_params = { from: @thread.config.email_from_proc.call(@thread) }

@comment_url = Commontator.comment_url(@comment, main_app)
@recipient_emails = recipients.map do |recipient|
Commontator.commontator_email(recipient, self)
end

params = Hash.new
params[:comment] = @comment
params[:thread] = @thread
params[:creator] = @creator
params[:creator_name] = @creator_name
params[:commontable_name] = @commontable_name
params[:comment_url] = @comment_url
@using_mailgun = Rails.application.config.action_mailer.delivery_method == :mailgun

if uses_mailgun?
@to = recipient_emails(recipients)
if @using_mailgun
@recipients_header = :to
@mailgun_recipient_variables = {}.tap do |mailgun_recipient_variables|
@recipient_emails.each { |email| mailgun_recipient_variables[email] = {} }
end
else
@to = t('commontator.email.undisclosed_recipients')
@bcc = recipient_emails(recipients)
@recipients_header = :bcc
end

@from = @thread.config.email_from_proc.call(@thread)
end
@mail_params[@recipients_header] = @recipient_emails

def recipient_emails(recipients)
recipients.collect{ |s| Commontator.commontator_email(s, self) }
end

def mailgun_recipient_variables(recipients)
recipient_emails(recipients).each_with_object({}) do |user_email, memo|
memo[user_email] = {}
end
end
@creator_name = Commontator.commontator_name(@creator)
@commontable_name = Commontator.commontable_name(@thread)
@comment_url = Commontator.comment_url(@comment, main_app)

def uses_mailgun?
Rails.application.config.action_mailer.delivery_method == :mailgun
@mail_params[:subject] = t(
'commontator.email.comment_created.subject',
creator_name: @creator_name,
commontable_name: @commontable_name,
comment_url: @comment_url
)
end
end
end
1 change: 0 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ de:
body: "%{creator_name} kommentierte zu %{commontable_name}:"
subject: "%{creator_name} veröffentlichte einen Kommentar zu %{commontable_name}"
thread_link_html: "<a href=\"%{comment_url}\">Hier klicken</a> um alle Kommentare zu %{commontable_name} zu sehen."
undisclosed_recipients: "Undisclosed Recipients"
require_login: "Sie müssen sich anmelden bevor sie einen Kommentar veröffentlichen können."
subscription:
actions:
Expand Down
53 changes: 26 additions & 27 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

---
en:
activerecord:
attributes:
commontator/comment:
---
en:
activerecord:
attributes:
commontator/comment:
body: Comment
creator: Creator
editor: Editor
thread: Discussion
commontator/subscription:
commontator/subscription:
subscriber: Subscriber
thread: Discussion
commontator/thread:
commontator/thread:
commontable: Commontable
models:
commontator/comment:
models:
commontator/comment:
one: comment
other: comments
commontator/subscription:
commontator/subscription:
one: subscription
other: subscriptions
commontator/thread:
commontator/thread:
one: thread
other: threads
commontator:
commontator:
anonymous: Anonymous
comment:
actions:
comment:
actions:
cancel: Cancel
confirm_delete: "Are you sure you want to delete this comment?"
create: "Post Comment"
Expand All @@ -55,33 +55,32 @@ en:
new: "New Comment"
undelete: Undelete
update: "Modify Comment"
errors:
errors:
already_deleted: "This comment has already been deleted."
create: "This comment could not be posted because:"
double_posted: "is a duplicate of another comment."
not_deleted: "This comment is not deleted."
update: "This comment could not be modified because:"
status:
status:
created_at: "Posted on %{created_at}."
deleted_by: "Comment deleted by %{deleter_name}."
updated_at: "Last modified by %{editor_name} on %{updated_at}."
email:
comment_created:
email:
comment_created:
body: "%{creator_name} commented on %{commontable_name}:"
subject: "%{creator_name} posted a comment on %{commontable_name}"
thread_link_html: "<a href=\"%{comment_url}\">Click here</a> to view all comments on %{commontable_name}."
undisclosed_recipients: "Undisclosed Recipients"
require_login: "You must login before you can post a comment."
subscription:
actions:
subscription:
actions:
confirm_unsubscribe: "Are you sure you want to unsubscribe from this discussion?"
subscribe: Subscribe
unsubscribe: Unsubscribe
errors:
errors:
already_subscribed: "You are already subscribed to this discussion."
not_subscribed: "You are not subscribed to this discussion."
thread:
actions:
thread:
actions:
show_all: "Show All Comments"
filter: "Filter Comments"
close: "Close Discussion"
Expand All @@ -92,10 +91,10 @@ en:
errors:
already_closed: "This discussion has already been closed."
not_closed: "This discussion is not closed."
status:
status:
cannot_post: "New comments cannot be posted at this time."
closed: "Comments (Closed by %{closer_name})"
open: Comments
time:
formats:
time:
formats:
commontator: "%b %d %Y at %I:%M%p %Z"
1 change: 0 additions & 1 deletion config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pt-BR:
body: "%{creator_name} comentou em %{commontable_name}:"
subject: "%{creator_name} postou um comentário em %{commontable_name}"
thread_link_html: "<a href=\"%{comment_url}\">Clique aqui</a> para ver todos os comentários em %{commontable_name}."
undisclosed_recipients: "Undisclosed Recipients"
require_login: "Você deve fazer login para postar um comentário."
subscription:
actions:
Expand Down
51 changes: 25 additions & 26 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
ru:
activerecord:
attributes:
commontator/comment:
ru:
activerecord:
attributes:
commontator/comment:
body: Комментарий
creator: Создал
editor: Редактировал
thread: Обсуждение
commontator/subscription:
commontator/subscription:
subscriber: Подписчик
thread: Обсуждение
commontator/thread:
commontator/thread:
commontable: Комментируем
models:
commontator/comment:
models:
commontator/comment:
one: комментарий
other: комментарии
commontator/subscription:
commontator/subscription:
one: подписка
other: подписки
commontator/thread:
commontator/thread:
one: обсуждение
other: обсуждения
commontator:
commontator:
anonymous: Аноним
comment:
actions:
comment:
actions:
cancel: Отменить
confirm_delete: "Вы уверены, что хотите удалить комментарий?"
create: "Оставить Комментарий"
Expand All @@ -33,33 +33,32 @@ ru:
new: "Новый Комментарий"
undelete: Восстановить
update: "Изменить Комментарий"
errors:
errors:
already_deleted: "Этот комментарий был удален."
create: "Комментарий нельзя оставить потому что"
double_posted: "этот комментарий уже есть."
not_deleted: "Этот комментарий не удален."
update: "Этот комментарий нельзя изменить потому что"
status:
status:
created_at: "Создан %{created_at}."
deleted_by: "Комментарий был удален %{deleter_name}."
updated_at: "Редактировал %{editor_name}, %{updated_at}."
email:
comment_created:
email:
comment_created:
body: "%{creator_name} комментировал %{commontable_name}:"
subject: "%{creator_name} оставил комментарий к %{commontable_name}"
thread_link_html: "<a href=\"%{comment_url}\">Нажмите здесь</a> чтобы посмотреть все комментарии к %{commontable_name}."
undisclosed_recipients: "Не указан получатель"
require_login: "Вы должны залогиниться прежде чем оставить комментарий."
subscription:
actions:
subscription:
actions:
confirm_unsubscribe: "Вы уверены, что хотите отписать от обсуждения?"
subscribe: Подписаться
unsubscribe: Отписаться
errors:
errors:
already_subscribed: "Вы уже подписаны на это обсуждение."
not_subscribed: "Вы не подписаны на это обсуждение."
thread:
actions:
thread:
actions:
show_all: "Показать все комментарии"
filter: "Фильтровать комментарии"
close: "Закрыть обсуждение"
Expand All @@ -70,10 +69,10 @@ ru:
errors:
already_closed: "Это обсуждение было закрыто."
not_closed: "Это обсуждение не закрыто."
status:
status:
cannot_post: "Новый комментарии нельзя разместить в данный момент."
closed: "Комментарии (Закрыты %{closer_name})"
open: Комментарии
time:
formats:
time:
formats:
commontator: "%b %d %Y в %I:%M%p %Z"
Loading

0 comments on commit 08d91e8

Please sign in to comment.