X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/8ecb53b8692cbaac262fba5b1baa632d7cef5353..a533d341f06afe23a6597b65293cb78c8799ca64:/app/models/user.rb 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