mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 11:13:38 +08:00
DEV: Accept force_respect_seen_recently
argument in UserEmail job (#16460)
This commit is contained in:
parent
f0d46c3549
commit
1e8a666003
|
@ -131,11 +131,14 @@ module Jobs
|
|||
end
|
||||
|
||||
seen_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
|
||||
end
|
||||
|
||||
email_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]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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" do
|
||||
upload = Fabricate(:upload)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user