A platform for community discussion. Free, open, simple.
DEV: Accept `force_respect_seen_recently` argument in UserEmail job (#16460)
Mark VanLandingham1e8a66600306
diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rbindex d63d17ea4ca..e69bf60a6e6 100644--- a/app/jobs/regular/user_email.rb+++ b/app/jobs/regular/user_email.rb@@ -131,11 +131,14 @@ module Jobsendseen_recently = (user.last_seen_at.present? && user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)- seen_recently = false if always_email_regular?(user, type) || always_email_private_message?(user, type) || user.staged+ if !args[:force_respect_seen_recently] &&+ (always_email_regular?(user, type) || always_email_private_message?(user, type) || user.staged)+ seen_recently = false+ endemail_args = {}- if (post || notification || notification_type) &&+ if (post || notification || notification_type || args[:force_respect_seen_recently]) &&(seen_recently && !user.suspended?)return skip_message(SkippedEmailLog.reason_types[:user_email_seen_recently])@@ -227,29 +230,27 @@ module Jobs# If this email has a related post, don't send an email if it's been deleted or seen recently.def skip_email_for_post(post, user)- if post- if post.topic.blank?- return SkippedEmailLog.reason_types[:user_email_topic_nil]- end+ return false unless post- if post.user.blank?- return SkippedEmailLog.reason_types[:user_email_post_user_deleted]- end+ if post.topic.blank?+ return SkippedEmailLog.reason_types[:user_email_topic_nil]+ end- if post.user_deleted?- return SkippedEmailLog.reason_types[:user_email_post_deleted]- end+ if post.user.blank?+ return SkippedEmailLog.reason_types[:user_email_post_user_deleted]+ end- if user.suspended? && (!post.user&.staff? || !post.user&.human?)- return SkippedEmailLog.reason_types[:user_email_user_suspended]- end+ if post.user_deleted?+ return SkippedEmailLog.reason_types[:user_email_post_deleted]+ end- already_read = user.user_option.email_level != UserOption.email_level_types[:always] && PostTiming.exists?(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id)- if already_read- SkippedEmailLog.reason_types[:user_email_already_read]- end- else- false+ if user.suspended? && (!post.user&.staff? || !post.user&.human?)+ return SkippedEmailLog.reason_types[:user_email_user_suspended]+ end++ already_read = user.user_option.email_level != UserOption.email_level_types[:always] && PostTiming.exists?(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id)+ if already_read+ SkippedEmailLog.reason_types[:user_email_already_read]endenddiff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rbindex 714289a4191..cb8c6708a98 100644--- a/spec/jobs/user_email_spec.rb+++ b/spec/jobs/user_email_spec.rb@@ -147,6 +147,20 @@ describe Jobs::UserEmail do)end+ it "doesn't send an email even if email_level is set to always if `force_respect_seen_recently` arg is true" do+ user.user_option.update(email_level: UserOption.email_level_types[:always])+ PostTiming.create!(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id, msecs: 100)++ Jobs::UserEmail.new.execute(+ type: :user_replied,+ user_id: user.id,+ post_id: post.id,+ notification_id: notification.id,+ force_respect_seen_recently: true+ )+ expect(ActionMailer::Base.deliveries).to eq([])+ end+it "sends an email with no gsub substitution bugs" doupload = Fabricate(:upload)