From f20b8bd412c9d6edb5fe97e61e6f90eae55a0194 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Tue, 11 Jan 2022 15:34:20 -0600 Subject: [PATCH] Prefer named comparison #after? to numeric comparison on times (#16057) ActiveSupport adds DateAndTime::Calculations#after? (and before?) - which clarifies intent (users newer than the relative time are skipped) of the early returns. --- .../broadcasts/welcome_notification/generator.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/broadcasts/welcome_notification/generator.rb b/app/services/broadcasts/welcome_notification/generator.rb index 701f471da..d47ddcbe0 100644 --- a/app/services/broadcasts/welcome_notification/generator.rb +++ b/app/services/broadcasts/welcome_notification/generator.rb @@ -37,7 +37,7 @@ module Broadcasts def send_welcome_notification return if - user.created_at > 3.hours.ago || + user.created_at.after?(3.hours.ago) || received_notification?(welcome_broadcast) || commented_on_welcome_thread? @@ -48,7 +48,7 @@ module Broadcasts def send_authentication_notification return if - user.created_at > 1.day.ago || + user.created_at.after?(1.day.ago) || authenticated_with_all_providers? || received_notification?(authentication_broadcast) @@ -58,7 +58,7 @@ module Broadcasts def send_feed_customization_notification return if - user.created_at > 3.days.ago || + user.created_at.after?(3.days.ago) || user_following_tags? || received_notification?(customize_feed_broadcast) @@ -67,7 +67,7 @@ module Broadcasts end def send_ux_customization_notification - return if user.created_at > 5.days.ago || received_notification?(customize_ux_broadcast) + return if user.created_at.after?(5.days.ago) || received_notification?(customize_ux_broadcast) Notification.send_welcome_notification(user.id, customize_ux_broadcast.id) @notification_enqueued = true @@ -75,7 +75,7 @@ module Broadcasts def send_discuss_and_ask_notification return if - user.created_at > 6.days.ago || + user.created_at.after?(6.days.ago) || (asked_a_question && started_a_discussion) || received_notification?(discuss_and_ask_broadcast) @@ -84,7 +84,7 @@ module Broadcasts end def send_download_app_notification - return if user.created_at > 7.days.ago || received_notification?(download_app_broadcast) + return if user.created_at.after?(7.days.ago) || received_notification?(download_app_broadcast) Notification.send_welcome_notification(user.id, download_app_broadcast.id) @notification_enqueued = true