has-friendship / has_friendship

Add friendship to ActiveRecord models
MIT License
198 stars 98 forks source link

Deleting the request by the requester? #51

Open AmitJoki opened 6 years ago

AmitJoki commented 6 years ago

Facebook allows to roll back the "Add Friend" request. I am looking for such a method in has_friendship

Like:

@mac.friend_request(@foo)
# The above one might be by mistake, mac doesn't really want to send a request to foo
# Allow the following
@mac.delete_request(@foo)
# Now mac can be happy

As of now, I have the following in my user.rb I think this will be an useful method to be incorporated into the gem.

def delete_request(f)
    HasFriendship::Friendship.find_by('friend_id = :cur and friendable_id = :other', cur: id, other: f.id).destroy
    HasFriendship::Friendship.find_by('friend_id = :other and friendable_id = :cur', cur: id, other: f.id).destroy
end
ganeshh123 commented 5 years ago

Add a link for Mac which calls the decline_request method for foo

chevinbrown commented 5 years ago

@AmitJoki I'm not opposed if you want to submit a PR, but I tend to agree with @ganeshh123.

ganeshh123 commented 5 years ago

Currently doing this right now

This is my method:

def cancel_request @user = current_user @newfriend @newfriend = User.find(params[:id]) @newfriend.decline_request(current_user) redirect_to @newfriend, flash: {notice: "Your friend request to " + @newfriend.name + " has been cancelled"} end

The link would be something like "/users/:id/cancel request"

Bit Late to answer, but hope this helps anyone else needing this feature