-
Notifications
You must be signed in to change notification settings - Fork 458
Expand file tree
/
Copy pathpush_created_mailer.rb
More file actions
36 lines (32 loc) 路 1.09 KB
/
Copy pathpush_created_mailer.rb
File metadata and controls
36 lines (32 loc) 路 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true
class PushCreatedMailer < ApplicationMailer
include PushesHelper
def notify
@push = params[:record]
locale = @push.notify_emails_to_locale.presence
I18n.with_locale(locale || I18n.default_locale) do
@secret_url = secret_url_for_push(@push, locale: locale)
@subject = "#{@push.user&.email.presence || _("Someone")} #{_("has sent you a Push")}"
# Full duration for email body (e.g. "7 day(s), 0 hour(s) and 0 minute(s)")
@duration_text = format_minutes_duration(@push.expire_after_days.to_i * 24 * 60)
mail(
to: Pwpush::NotifyEmailsTo.parse_emails(@push.notify_emails_to),
subject: @subject
)
end
end
private
def secret_url_for_push(push, locale: nil)
raw_url = if push.retrieval_step
preliminary_push_url(push)
else
push_url(push)
end
base = raw_url.split("?").first
if locale.present? && Array(Settings.enabled_language_codes).include?(locale.to_s)
base += "?locale=#{locale}"
end
base = base.gsub(/http/i, "https") if ENV.key?("FORCE_SSL")
base
end
end