Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on Unblock Friend. #34

Open
krunalbabaria opened this issue Jun 2, 2016 · 13 comments
Open

Issue on Unblock Friend. #34

krunalbabaria opened this issue Jun 2, 2016 · 13 comments

Comments

@krunalbabaria
Copy link

krunalbabaria commented Jun 2, 2016

I am phasing one issue on unblock. when i perform block at that time only status change. but when i unblock perform at that time entry remove from table instead of status change.

So after unblock no and relation with one user to another for friend.

Example .

 # @mac sends a friend request to @dee
  1 ) @mac.friend_request(@dee)

@dee can accept the friend request 
 2) @dee.accept_request(@mac)

 # @mac blocks @dee from making any more friendship actions
3) @mac.block_friend(@dee)

# @mac unblocks @dee
# Only @mac can perform this action
4)@mac.unblock_friend(@dee)

after doing this @mac and @dee not friends because of record delete.

@sungwoncho
Copy link
Collaborator

sungwoncho commented Jun 3, 2016

When we first implemented block_friend, it was for blocking someone from making a friend request. That is why unblock_friend just destroys the existing friendship (see here).

But I see that it is useful to block/unblock a friend. On top of my head, a solution would be to have 2 different status for blocked friendship. Maybe blocked_friend, blocked_non_friend (see here). That way we can implement unblock_friend method to either destroy or restore friendship.

Let me know if you have other suggestions.

Edit

I also see that method name unblock_friend is kind of strange because you can unblock non-friends as well.

@derekcannon
Copy link

Just to jump in on this, I think that unblock_friend performing two different functions depending on the state of the blocked individual (whether he is a friend or not) is a little weird. I think it would be better to make two explicit methods for these. Thoughts?

@krtschmr
Copy link

krtschmr commented Mar 24, 2017

block somebody should not rely on a friendship request
in general, i can make friendships, but out of nothing i can block friends.

dee.block(tim)
tim.blocked_by?(dee) # true

dee.friend_request(tim) # false, exception

if we have been friends, and somehow a friend blocks another, then the friendships is cancelled.

@Pensarfeo
Copy link
Collaborator

@krtschmr : do you mean you should be able to block people even if you do not have any type of relation with them? Why would that happen withing the scope of this gem?
I agree though, the naming of the method is misleading (my bad :). Unblock friend would imply resetting back the friendship rather than destroying the relation.

@krtschmr
Copy link

krtschmr commented Mar 24, 2017 via email

@Pensarfeo
Copy link
Collaborator

I see in which context you want to use the gem. This functionality could be added fairly easily. In the mean time you could just create a friendship and block it in the same controller.

@mac.friend_request(@dee)
@dee.accept_request(@mac)
@mac.block_friend(@dee)

@krtschmr
Copy link

krtschmr commented Mar 24, 2017 via email

@Pensarfeo
Copy link
Collaborator

What you want to do goes a bit outside of the scope of the gem. However I should be easy for you to add that functionality!

@krtschmr
Copy link

krtschmr commented Mar 27, 2017

I come back to this.
The problem here is that we get weired behaviours. a blocked relationship should only be unblockable by the bloder

  def block_somebody!(friend)
    friend_request(friend)
    block_friend(friend)
  end

this blocks anything without an active friendship, so current_user.block_somebody!(annoying_user)

User.first.block_somebody! User.last

User.first.blocked_friends
=> [#<User id: 9, name: "....

User.last.unblock_friend User.first

User.first.blocked_friends
=> []

this can only be "falsy"

actually, is this a bug? maybe i should make own issue for that

@krtschmr
Copy link

krtschmr commented Mar 27, 2017

i think a more universal use-case would be


  def friend_with?(user)
    # A friended B
    a.friend_with?(b) # false
    b.friend_with?(a) # false
    # B approved
    a.friend_with?(b) # true
    b.friend_with?(a) # true
  end

  def pending_friend_request?(user)
    # A friended B
    a.pending_friend_request?(b) # true
    b.pending_friend_request?(a) # true
  end

  def blocked_by?(user)
    # A Blocked B
    a.blocked_by?(b) # false
    b.blocked_by?(a) # true
  end

  def blocked?(user)
    # A Blocked B
    a.blocked?(b) # true
    b.blocked?(a) # false
  end

seems like i'll make this myself as hijacking work-arounds into your gem would be oversized.

my approach would be


  has_many :relations, class_name: "User::Relation"
  has_many :friends, -> { where relations: {type: :friendship, state: :confirmed } }, through: :relations, source: :user
  has_many :pending_friendships, -> { where relations: {type: :friendship, state: :pending } }, through: :relations, source: :user
  has_many :blocked_users, -> { where relations: {type: :block } }, through: :relations, source: :user

We create 2 relations to become friend, if one decides to block him the friendship is literally over. the own friendship will be converted into a block and the other friendship will be removed. i can write some tests and show you.
what do you think about this approach?

@krtschmr
Copy link

krtschmr commented Mar 27, 2017

https://gist.github.com/krtschmr/c9cb75ad364140ee5b6b953a1b1bb0cf

allright, now i finished it myself, with all specs that we need. fitting us like a charme. feel free to take it as an inspiration and implement any of my ideas into your great gem.

@stingrayzboy
Copy link

Hi All,
I have made my entire functionality based on this gem.
The fault with the blocking mechanism is its actually trying to alter the actual friendship by executing on both of them.
Granted for the Friend request there will be 2 entries.
But suppose if A and B are friends
A blocks B we shouldn't change the status of both the records to 3(blocked)
Rather the entry should be only in A so that A.blocked_friends shows B and not vice-versa
So with this approach the Unblock method will again change the status to 2 (friends)

All this while B still had A in his friend listing as B had not Blocked A
there should be A method called has_been_blocked where B will get to know if he is blocked by A
B.has_been_blocked A #=> true
this method can be used by the functionalities to implement the Block UnBlock Mechanism Properly.

@krtschmr
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants