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

Either friend can unblock a blocked friendship #81

Open
toddsutt opened this issue Feb 20, 2021 · 6 comments
Open

Either friend can unblock a blocked friendship #81

toddsutt opened this issue Feb 20, 2021 · 6 comments

Comments

@toddsutt
Copy link

toddsutt commented Feb 20, 2021

The blocker_id is not consistent between the two friendship objects, therefore either user can unblock a blocked friendship.

2.6.1 :059 > user1.friend_request(user2)
HasFriendship::Friendship Exists (0.4ms) SELECT 1 AS one FROM "friendships" WHERE "friendships"."friendable_id" = $1 AND "friendships"."friendable_type" = $2 AND "friendships"."friend_id" = $3 LIMIT $4 [["friendable_id", 1], ["friendable_type", "User"], ["friend_id", 49], ["LIMIT", 1]]
(0.1ms) BEGIN
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 49], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
HasFriendship::Friendship Create (0.2ms) INSERT INTO "friendships" ("friendable_type", "friendable_id", "friend_id", "created_at", "updated_at", "status") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["friendable_type", "User"], ["friendable_id", 1], ["friend_id", 49], ["created_at", "2021-02-20 05:40:37.589275"], ["updated_at", "2021-02-20 05:40:37.589275"], ["status", 0]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 49], ["LIMIT", 1]]
HasFriendship::Friendship Create (0.2ms) INSERT INTO "friendships" ("friendable_type", "friendable_id", "friend_id", "created_at", "updated_at", "status") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["friendable_type", "User"], ["friendable_id", 49], ["friend_id", 1], ["created_at", "2021-02-20 05:40:37.591793"], ["updated_at", "2021-02-20 05:40:37.591793"], ["status", 1]]
(5.5ms) COMMIT
=> true
2.6.1 :060 > user2.block_friend(user1)
(0.1ms) BEGIN
HasFriendship::Friendship Load (0.2ms) SELECT "friendships".* FROM "friendships" WHERE "friendships"."friendable_id" = $1 AND "friendships"."friendable_type" = $2 AND "friendships"."friend_id" = $3 AND "friendships"."status" != $4 ORDER BY "friendships"."id" ASC LIMIT $5 [["friendable_id", 49], ["friendable_type", "User"], ["friend_id", 1], ["status", 3], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 49], ["LIMIT", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
HasFriendship::Friendship Update (0.3ms) UPDATE "friendships" SET "status" = $1, "blocker_id" = $2, "updated_at" = $3 WHERE "friendships"."id" = $4 [["status", 3], ["blocker_id", 49], ["updated_at", "2021-02-20 05:40:51.383270"], ["id", 8]]
HasFriendship::Friendship Load (0.1ms) SELECT "friendships".* FROM "friendships" WHERE "friendships"."friendable_id" = $1 AND "friendships"."friendable_type" = $2 AND "friendships"."friend_id" = $3 AND "friendships"."status" != $4 ORDER BY "friendships"."id" ASC LIMIT $5 [["friendable_id", 1], ["friendable_type", "User"], ["friend_id", 49], ["status", 3], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 49], ["LIMIT", 1]]
HasFriendship::Friendship Update (0.3ms) UPDATE "friendships" SET "status" = $1, "blocker_id" = $2, "updated_at" = $3 WHERE "friendships"."id" = $4 [["status", 3], ["blocker_id", 1], ["updated_at", "2021-02-20 05:40:51.386480"], ["id", 7]]
(5.4ms) COMMIT
=> true
2.6.1 :061 > HasFriendship::Friendship.first
HasFriendship::Friendship Load (0.3ms) SELECT "friendships".* FROM "friendships" ORDER BY "friendships"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> #<HasFriendship::Friendship id: 7, friendable_type: "User", friendable_id: 1, friend_id: 49, created_at: "2021-02-20 05:40:37", updated_at: "2021-02-20 05:40:51", blocker_id: 1, status: "blocked">
2.6.1 :062 > HasFriendship::Friendship.last
HasFriendship::Friendship Load (0.4ms) SELECT "friendships".* FROM "friendships" ORDER BY "friendships"."id" DESC LIMIT $1 [["LIMIT", 1]]
=> #<HasFriendship::Friendship id: 8, friendable_type: "User", friendable_id: 49, friend_id: 1, created_at: "2021-02-20 05:40:37", updated_at: "2021-02-20 05:40:51", blocker_id: 49, status: "blocked">


The blocker_id is always getting set to the friendable_id. Instead, the blocker_id should be set to the id of the friend who called block!

@toddsutt
Copy link
Author

I created a pull request for this: #82. This is the first pull request I've ever done, let me know if I need to change anything. Hope this helps!

@toddsutt
Copy link
Author

Is this a dead gem? Should I be using a different gem for friends or just write my own?

@toddsutt
Copy link
Author

@chevinbrown I see you've done quite a few updates here, do you know if this gem is still supported?

@toddsutt
Copy link
Author

toddsutt commented Mar 3, 2021

I'll assume this gem is not supported anymore. Will use my own fork. Let me know if anyone comes back and sees this please!

@chevinbrown
Copy link
Contributor

@toddsutt you're right, this really isn't maintained anymore. I hopped on a few years ago to help get some releases out that I needed, but I don't have any remote connection to this gem any longer...seems like there's still sufficient interest in the community, are people interested in taking over maintainership?

@toddsutt
Copy link
Author

@chevinbrown I did fix this bug for myself and am using my own forked version. I will probably be using this for my business for a long time so I guess I will be minimally maintaining it for myself at least.

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

2 participants