mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +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
|
end
|
||||||
|
|
||||||
seen_recently = (user.last_seen_at.present? && user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
|
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 = {}
|
email_args = {}
|
||||||
|
|
||||||
if (post || notification || notification_type) &&
|
if (post || notification || notification_type || args[:force_respect_seen_recently]) &&
|
||||||
(seen_recently && !user.suspended?)
|
(seen_recently && !user.suspended?)
|
||||||
|
|
||||||
return skip_message(SkippedEmailLog.reason_types[:user_email_seen_recently])
|
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.
|
# 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)
|
def skip_email_for_post(post, user)
|
||||||
if post
|
return false unless post
|
||||||
if post.topic.blank?
|
|
||||||
return SkippedEmailLog.reason_types[:user_email_topic_nil]
|
|
||||||
end
|
|
||||||
|
|
||||||
if post.user.blank?
|
if post.topic.blank?
|
||||||
return SkippedEmailLog.reason_types[:user_email_post_user_deleted]
|
return SkippedEmailLog.reason_types[:user_email_topic_nil]
|
||||||
end
|
end
|
||||||
|
|
||||||
if post.user_deleted?
|
if post.user.blank?
|
||||||
return SkippedEmailLog.reason_types[:user_email_post_deleted]
|
return SkippedEmailLog.reason_types[:user_email_post_user_deleted]
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.suspended? && (!post.user&.staff? || !post.user&.human?)
|
if post.user_deleted?
|
||||||
return SkippedEmailLog.reason_types[:user_email_user_suspended]
|
return SkippedEmailLog.reason_types[:user_email_post_deleted]
|
||||||
end
|
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 user.suspended? && (!post.user&.staff? || !post.user&.human?)
|
||||||
if already_read
|
return SkippedEmailLog.reason_types[:user_email_user_suspended]
|
||||||
SkippedEmailLog.reason_types[:user_email_already_read]
|
end
|
||||||
end
|
|
||||||
else
|
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)
|
||||||
false
|
if already_read
|
||||||
|
SkippedEmailLog.reason_types[:user_email_already_read]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,20 @@ describe Jobs::UserEmail do
|
||||||
)
|
)
|
||||||
end
|
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
|
it "sends an email with no gsub substitution bugs" do
|
||||||
upload = Fabricate(:upload)
|
upload = Fabricate(:upload)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user