From 32bae48fd37142eada28a017e27047bbc8057609 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 12 Mar 2019 01:58:14 +0200 Subject: [PATCH] DEV: Use User#human? User#bot? (#7140) --- app/jobs/scheduled/pending_users_reminder.rb | 2 +- app/models/user.rb | 4 ++++ app/services/post_alerter.rb | 5 ++--- lib/post_creator.rb | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/jobs/scheduled/pending_users_reminder.rb b/app/jobs/scheduled/pending_users_reminder.rb index 88c2fa4db33..85bedc6781c 100644 --- a/app/jobs/scheduled/pending_users_reminder.rb +++ b/app/jobs/scheduled/pending_users_reminder.rb @@ -20,7 +20,7 @@ module Jobs if count > 0 target_usernames = Group[:moderators].users.map do |user| - next if user.id < 0 + next if user.bot? unseen_count = user.notifications.joins(:topic) .where("notifications.id > ?", user.seen_notification_id) diff --git a/app/models/user.rb b/app/models/user.rb index 97c8440a9a0..d47cc92c37e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -294,6 +294,10 @@ class User < ActiveRecord::Base self.id > 0 end + def bot? + !self.human? + end + def effective_locale if SiteSetting.allow_user_locale && self.locale.present? self.locale diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 632029fbddb..454f981c078 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -13,7 +13,7 @@ class PostAlerter def not_allowed?(user, post) user.blank? || - user.id < 0 || + user.bot? || user.id == post.user_id end @@ -279,8 +279,7 @@ class PostAlerter DiscourseEvent.trigger(:before_create_notification, user, type, post, opts) - return if user.blank? - return if user.id < 0 + return if user.blank? || user.bot? is_liked = type == Notification.types[:liked] return if is_liked && user.user_option.like_notification_frequency == UserOption.like_notification_frequency_type[:never] diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 6d88d1adf26..77cc5d0407f 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -514,7 +514,7 @@ class PostCreator end def create_post_notice - return if @user.id < 0 || @user.staged + return if @user.bot? || @user.staged last_post_time = Post.where(user_id: @user.id) .order(created_at: :desc)