X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/0e78061cdba5cfb3f299f57b7643d2b396ee235b..a71b8af4d1bded364c0ba7f05c8dd851a4a19859:/app/models/user.rb?ds=inline diff --git a/app/models/user.rb b/app/models/user.rb index 26a9f33e1..3dbaa688c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -305,6 +305,15 @@ class User < ApplicationRecord 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