diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b3379b91a1..fa15ea90a0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,7 +112,6 @@ Rails/ActionControllerFlashBeforeRender: Exclude: - 'app/controllers/application_controller.rb' - 'app/controllers/confirmations_controller.rb' - - 'app/controllers/friendships_controller.rb' - 'app/controllers/issue_comments_controller.rb' - 'app/controllers/messages_controller.rb' - 'app/controllers/passwords_controller.rb' @@ -142,7 +141,6 @@ Rails/InverseOf: Exclude: - 'app/models/changeset.rb' - 'app/models/diary_entry.rb' - - 'app/models/friendship.rb' - 'app/models/issue.rb' - 'app/models/message.rb' - 'app/models/note.rb' diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index d267777c19..39d6191cd8 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -13,20 +13,20 @@ class FollowsController < ApplicationController before_action :lookup_friend def show - @already_follows = current_user.friends_with?(@friend) + @already_follows = current_user.follows?(@friend) end def create follow = Follow.new follow.follower = current_user follow.following = @friend - if current_user.friends_with?(@friend) + if current_user.follows?(@friend) flash[:warning] = t ".already_followed", :name => @friend.display_name - elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_friends_per_hour + elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_follows_per_hour flash[:error] = t ".limit_exceeded" elsif follow.save flash[:notice] = t ".success", :name => @friend.display_name - UserMailer.friendship_notification(follow).deliver_later + UserMailer.follow_notification(follow).deliver_later else follow.add_error(t(".failed", :name => @friend.display_name)) end @@ -37,7 +37,7 @@ def create end def destroy - if current_user.friends_with?(@friend) + if current_user.follows?(@friend) Follow.where(:follower => current_user, :following => @friend).delete_all flash[:notice] = t ".success", :name => @friend.display_name else diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index fea73c710c..6098162852 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -119,7 +119,7 @@ def diary_comment_notification(comment, recipient) end end - def friendship_notification(follow) + def follow_notification(follow) with_recipient_locale follow.following do @follow = follow @viewurl = user_url(@follow.follower) diff --git a/app/models/user.rb b/app/models/user.rb index ec3883bc6f..16f733c882 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,8 +282,8 @@ def distance(nearby_user) OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon) end - def friends_with?(new_friend) - follows.exists?(:following => new_friend) + def follows?(user) + follows.exists?(:following => user) end ## @@ -411,12 +411,12 @@ def max_messages_per_hour max_messages.clamp(0, Settings.max_messages_per_hour) end - def max_friends_per_hour + def max_follows_per_hour account_age_in_seconds = Time.now.utc - created_at account_age_in_hours = account_age_in_seconds / 3600 - recent_friends = Follow.where(:following => self).where(:created_at => Time.now.utc - 3600..).count - max_friends = account_age_in_hours.ceil + recent_friends - (active_reports * 10) - max_friends.clamp(0, Settings.max_friends_per_hour) + recent_follows = Follow.where(:following => self).where(:created_at => Time.now.utc - 3600..).count + max_follows = account_age_in_hours.ceil + recent_follows - (active_reports * 10) + max_follows.clamp(0, Settings.max_follows_per_hour) end def max_changeset_comments_per_hour diff --git a/app/views/dashboards/_contact.html.erb b/app/views/dashboards/_contact.html.erb index 4547a2d751..8e78524dec 100644 --- a/app/views/dashboards/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -35,7 +35,7 @@
<%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %>
- <% unless @follow.following.friends_with?(@follow.follower) -%> + <% unless @follow.following.follows?(@follow.follower) -%><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %>
<% end -%> <% end %> diff --git a/app/views/user_mailer/friendship_notification.text.erb b/app/views/user_mailer/follow_notification.text.erb similarity index 78% rename from app/views/user_mailer/friendship_notification.text.erb rename to app/views/user_mailer/follow_notification.text.erb index 624ba92b76..7f9ba202ef 100644 --- a/app/views/user_mailer/friendship_notification.text.erb +++ b/app/views/user_mailer/follow_notification.text.erb @@ -4,6 +4,6 @@ <%= t '.see_their_profile', :userurl => @viewurl %> -<% unless @follow.following.friends_with?(@follow.follower) -%> +<% unless @follow.following.follows?(@follow.follower) -%> <%= t '.follow_them', :followurl => @followurl %> <% end -%> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 76bedf60e6..b2247c0d01 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -83,7 +83,7 @@ <% if current_user %>