]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Set updated_by when resolving issues
[rails.git] / app / models / user.rb
index 26a9f33e153bf04c92d81335577bf37ded97bd27..3dbaa688c966643a92707cd2ae7cf48586713068 100644 (file)
@@ -305,6 +305,15 @@ class User < ApplicationRecord
     max_messages.clamp(0, Settings.max_messages_per_hour)
   end
 
     max_messages.clamp(0, Settings.max_messages_per_hour)
   end
 
+  def max_friends_per_hour
+    account_age_in_seconds = Time.now.utc - creation_time
+    account_age_in_hours = account_age_in_seconds / 3600
+    recent_friends = Friendship.where(:befriendee => self).where("created_at >= ?", Time.now.utc - 3600).count
+    active_reports = issues.with_status(:open).sum(:reports_count)
+    max_friends = account_age_in_hours.ceil + recent_friends - active_reports * 10
+    max_friends.clamp(0, Settings.max_friends_per_hour)
+  end
+
   private
 
   def set_defaults
   private
 
   def set_defaults