diaspora/app/mailers/notifier.rb
Alec Leamas eacee54846 Replace APP_CONFIG[:terse_pod_url] with uri object.
Adds a new APP_CONFIG[:pod_uri] item, an uri object parsed from
pod_url. Replace all occurrences of APP_CONFIG[:terse_pod_url] with
APP_CONFIG[:pod_uri].host. Closes http://bugs.joindiaspora.com/issues/684,
using the well-defined semantics of the uri object.

The pod_url is normalized using module URI's functions, always with a
trailing /.

The diaspora-handle will always reflect the pod_url with this patch
i. e., a pod_url like www.dpod.se will give the handle xx@www.dpod.se;
previous code stripped the www. prefix. If this is a problem, it
should be addressed by another setting, since one cannot presume that
www.domain.tld resolves to the same address as domain.tld.
2010-12-10 14:29:19 +01:00

59 lines
2 KiB
Ruby

class Notifier < ActionMailer::Base
default :from => APP_CONFIG[:smtp_sender_address]
ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png")
def self.admin(string, recipients, opts = {})
mails = []
recipients.each do |rec|
mail = single_admin(string, rec)
mails << mail
mail.deliver
end
mails
end
def single_admin(string, recipient)
@recipient = recipient
@string = string.html_safe
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => @recipient.email,
:subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:pod_uri].host)
end
def new_request(recipient_id, sender_id)
@receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_id)
log_mail(recipient_id, sender_id, 'new_request')
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => APP_CONFIG[:pod_uri].host)
end
def request_accepted(recipient_id, sender_id, aspect_id)
@receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_id)
@aspect = Aspect.find_by_id(aspect_id)
log_mail(recipient_id, sender_id, 'request_accepted')
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => APP_CONFIG[:pod_uri].host)
end
private
def log_mail recipient_id, sender_id, type
log_string = "event=mail mail_type=#{type} db_name=#{MongoMapper.database.name} recipient_id=#{recipient_id} sender_id=#{sender_id}"
if @receiver && @sender
log_string << "models_found=true sender_handle=#{@sender.diaspora_handle} recipient_handle=#{@receiver.diaspora_handle}"
else
log_string << "models_found=false"
end
Rails.logger.info log_string
end
end