2013-06-11 04:46:08 +08:00
|
|
|
require_dependency 'email/message_builder'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
class InviteMailer < ActionMailer::Base
|
2013-06-11 04:46:08 +08:00
|
|
|
include Email::BuildEmailHelper
|
2013-02-07 23:45:24 +08:00
|
|
|
|
2016-06-06 01:22:46 +08:00
|
|
|
class UserNotificationRenderer < ActionView::Base
|
|
|
|
include UserNotificationsHelper
|
2017-04-25 03:26:06 +08:00
|
|
|
include EmailHelper
|
2016-06-06 01:22:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_invite(invite, custom_message=nil)
|
2013-02-06 03:16:51 +08:00
|
|
|
# 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
|
2015-02-06 00:43:30 +08:00
|
|
|
if SiteSetting.enable_names && invite.invited_by.name.present?
|
2014-07-10 13:27:40 +08:00
|
|
|
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
|
2013-11-07 01:56:26 +08:00
|
|
|
if first_topic.present?
|
2014-07-09 01:03:11 +08:00
|
|
|
# get topic excerpt
|
|
|
|
topic_excerpt = ""
|
|
|
|
if first_topic.excerpt
|
2016-06-11 10:37:33 +08:00
|
|
|
topic_excerpt = first_topic.excerpt.tr("\n", " ")
|
2014-07-09 01:03:11 +08:00
|
|
|
end
|
|
|
|
|
2016-06-08 20:34:25 +08:00
|
|
|
template = 'invite_mailer'
|
|
|
|
if custom_message.present?
|
|
|
|
template = 'custom_invite_mailer'
|
|
|
|
end
|
2016-06-08 01:24:45 +08:00
|
|
|
|
2017-04-25 03:26:06 +08:00
|
|
|
topic_title = first_topic.try(:title)
|
|
|
|
if SiteSetting.private_email?
|
2017-04-27 23:45:49 +08:00
|
|
|
topic_title = I18n.t("system_messages.private_topic_title", id: first_topic.id)
|
2017-04-25 03:26:06 +08:00
|
|
|
topic_excerpt = ""
|
|
|
|
end
|
|
|
|
|
2013-11-07 01:56:26 +08:00
|
|
|
build_email(invite.email,
|
2016-06-08 20:34:25 +08:00
|
|
|
template: template,
|
2014-07-09 01:03:11 +08:00
|
|
|
invitee_name: invitee_name,
|
2014-07-10 12:33:09 +08:00
|
|
|
site_domain_name: Discourse.current_hostname,
|
2013-11-07 01:56:26 +08:00
|
|
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
2017-04-25 03:26:06 +08:00
|
|
|
topic_title: topic_title,
|
2014-07-09 01:03:11 +08:00
|
|
|
topic_excerpt: topic_excerpt,
|
2014-06-15 06:49:19 +08:00
|
|
|
site_description: SiteSetting.site_description,
|
2016-06-08 20:34:25 +08:00
|
|
|
site_title: SiteSetting.title,
|
|
|
|
user_custom_message: custom_message)
|
2013-11-07 01:56:26 +08:00
|
|
|
else
|
2016-06-08 20:34:25 +08:00
|
|
|
template = 'invite_forum_mailer'
|
|
|
|
if custom_message.present?
|
|
|
|
template = 'custom_invite_forum_mailer'
|
|
|
|
end
|
|
|
|
|
2013-11-07 01:56:26 +08:00
|
|
|
build_email(invite.email,
|
2016-06-08 20:34:25 +08:00
|
|
|
template: template,
|
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,
|
2016-06-08 20:34:25 +08:00
|
|
|
site_title: SiteSetting.title,
|
|
|
|
user_custom_message: custom_message)
|
2013-11-07 01:56:26 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2014-10-10 23:47:52 +08:00
|
|
|
def send_password_instructions(user)
|
|
|
|
if user.present?
|
|
|
|
email_token = user.email_tokens.create(email: user.email)
|
|
|
|
build_email(user.email,
|
|
|
|
template: 'invite_password_instructions',
|
|
|
|
email_token: email_token.token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|