discourse/app/mailers/invite_mailer.rb

46 lines
1.6 KiB
Ruby
Raw Normal View History

require_dependency 'email/message_builder'
2013-02-06 03:16:51 +08:00
class InviteMailer < ActionMailer::Base
include Email::BuildEmailHelper
2013-02-07 23:45:24 +08:00
2013-02-06 03:16:51 +08:00
def send_invite(invite)
# Find the first topic they were invited to
first_topic = invite.topics.order(:created_at).first
2014-07-10 13:27:40 +08:00
# get invitee name (based on site setting)
invitee_name = invite.invited_by.username
if (SiteSetting.enable_names)
invitee_name = "#{invite.invited_by.name} (#{invite.invited_by.username})"
end
2013-02-06 03:16:51 +08:00
# If they were invited to a topic
if first_topic.present?
# get topic excerpt
topic_excerpt = ""
if first_topic.excerpt
topic_excerpt = first_topic.excerpt.gsub("\n", " ")
end
build_email(invite.email,
template: 'invite_mailer',
invitee_name: invitee_name,
site_domain_name: Discourse.current_hostname,
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
2014-06-15 06:49:19 +08:00
topic_title: first_topic.try(:title),
topic_excerpt: topic_excerpt,
2014-06-15 06:49:19 +08:00
site_description: SiteSetting.site_description,
site_title: SiteSetting.title)
else
build_email(invite.email,
template: 'invite_forum_mailer',
2014-07-10 13:27:40 +08:00
invitee_name: invitee_name,
site_domain_name: Discourse.current_hostname,
2014-06-15 06:49:19 +08:00
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
site_description: SiteSetting.site_description,
site_title: SiteSetting.title)
end
2013-02-06 03:16:51 +08:00
end
end