From a07204111a83813d0dc73c48cd63168ebc63991b Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Wed, 1 Jun 2022 15:24:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=82=AE=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=94=A8=E6=88=B7=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/send_template_message_job.rb | 9 ++++++++- app/models/message_template/custom_tip.rb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index bec3f7b08..557d4d0fa 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -8,13 +8,20 @@ class SendTemplateMessageJob < ApplicationJob receivers_id, template_id, props = args[0], args[1], args[2] template = MessageTemplate.find_by_id(template_id) 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) 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_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) 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' watcher_id = args[0] watcher = Watcher.find_by_id(watcher_id) diff --git a/app/models/message_template/custom_tip.rb b/app/models/message_template/custom_tip.rb index 6c5a3345d..f1e3096f8 100644 --- a/app/models/message_template/custom_tip.rb +++ b/app/models/message_template/custom_tip.rb @@ -48,4 +48,21 @@ class MessageTemplate::CustomTip < MessageTemplate Rails.logger.info("MessageTemplate::CustomTip.get_email_message_content [ERROR] #{e}") return '', '', '' 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 \ No newline at end of file