通知邮件支持用户不存在时发送
This commit is contained in:
parent
4a23878185
commit
7290cd6495
|
@ -8,13 +8,20 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_id, template_id, props = args[0], args[1], args[2]
|
receivers_id, template_id, props = args[0], args[1], args[2]
|
||||||
template = MessageTemplate.find_by_id(template_id)
|
template = MessageTemplate.find_by_id(template_id)
|
||||||
return unless template.present?
|
return unless template.present?
|
||||||
receivers = User.where(id: receivers_id)
|
receivers = User.where(id: receivers_id).or(User.where(mail: receivers_id))
|
||||||
|
not_exists_receivers = receivers_id - receivers.pluck(:id) - receivers.pluck(:mail)
|
||||||
receivers_string, content, notification_url = MessageTemplate::CustomTip.get_message_content(receivers, template, props)
|
receivers_string, content, notification_url = MessageTemplate::CustomTip.get_message_content(receivers, template, props)
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {receivers_id: receivers_id, template_id: template_id, props: props})
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {receivers_id: receivers_id, template_id: template_id, props: props})
|
||||||
receivers.find_each do |receiver|
|
receivers.find_each do |receiver|
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::CustomTip.get_email_message_content(receiver, template, props)
|
receivers_email_string, email_title, email_content = MessageTemplate::CustomTip.get_email_message_content(receiver, template, props)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
|
not_exists_receivers.each do |mail|
|
||||||
|
valid_email_regex = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i
|
||||||
|
next unless (mail =~ valid_email_regex)
|
||||||
|
email_title, email_content = MessageTemplate::CustomTip.get_email_content(template, props)
|
||||||
|
Notice::Write::EmailCreateService.call(mail, email_title, email_content)
|
||||||
|
end
|
||||||
when 'FollowTip'
|
when 'FollowTip'
|
||||||
watcher_id = args[0]
|
watcher_id = args[0]
|
||||||
watcher = Watcher.find_by_id(watcher_id)
|
watcher = Watcher.find_by_id(watcher_id)
|
||||||
|
|
|
@ -48,4 +48,21 @@ class MessageTemplate::CustomTip < MessageTemplate
|
||||||
Rails.logger.info("MessageTemplate::CustomTip.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.get_email_content(template, props = {})
|
||||||
|
return '', '', '' if template.blank?
|
||||||
|
title = template.email_title
|
||||||
|
content = template.email
|
||||||
|
props.each do |k, v|
|
||||||
|
title.gsub!("{#{k}}", v)
|
||||||
|
content.gsub!("{#{k}}", v)
|
||||||
|
end
|
||||||
|
title.gsub!('{platform}', PLATFORM)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return title, content
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_content [ERROR] #{e}")
|
||||||
|
return '', ''
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue