Fix for sending unlimited duplicate friend requests

This commit is contained in:
Thomas Krehbiel 2010-09-22 18:05:11 -04:00 committed by root
parent aaa4d75a5e
commit 10e6ff9df8
2 changed files with 5 additions and 2 deletions

View file

@ -47,8 +47,8 @@ class RequestsController < ApplicationController
begin
@request = current_user.send_friend_request_to(rel_hash[:friend], aspect)
rescue Exception => e
raise e unless e.message.include? "already friends"
flash[:notice] = "You are already friends with #{params[:request][:destination_url]}!"
raise e unless e.message.include? "already"
flash[:notice] = "#{e.message} #{params[:request][:destination_url]}"
respond_with :location => aspect
return
end

View file

@ -8,6 +8,9 @@ module Diaspora
module UserModules
module Friending
def send_friend_request_to(desired_friend, aspect)
# should have different exception types for these?
raise "You have already sent a friend request to that person!" if self.pending_requests.detect{
|x| x.destination_url == desired_friend.receive_url }
raise "You are already friends with that person!" if self.friends.detect{
|x| x.receive_url == desired_friend.receive_url}
request = Request.instantiate(