Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security - how to implement blocking functionality between users in android app so that they can't reach each other anymore

I'm working on an android app which is using Firestore as its database. It is a chatting/dating app similar to Tinder, searching for users nearby to chat with. so, guys, I need your help in "blocking user" feature like if user1 block user2 due to any reason I want to show that blocked user2 in a list of blocked users activity inside the user1 app and obviously both the users should not see each other anywhere in the app not even in the searches just like tinder.

And later on, if the user1 decides to unblock user2, user2 should start appearing on the searches again.

So please help me out guys. i'm stuck here and don't know how to accomplish it. so please help and thank you guys in advance. i know you will help me out for sure.

like image 634
Aditya Tandon Avatar asked Nov 01 '25 18:11

Aditya Tandon


1 Answers

Assuming that you have a collection of users in which every user is a document within users collection, to solve this I recommend you to add a new property of type array under each user object like this:

Firestore-root
   |
   --- users (collection)
        |
        --- uid (document)
             |
             --- blockedUsers: ["friendUid", "friendUid"]
             |
             --- //other user properties

When you are searching the nearby users, add each user that you find to a list. Having a list of all the nearby users you can now check if the user that is searching the nearby users is in the blockedUsers list or not. You can achieve this using a Query that looks like this:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
Query query = rootRef.collection("users").whereArrayContains("blockedUsers", uid);

In this way you can display to the user only the nearby users that have or have not added him to blocked list.

like image 160
Alex Mamo Avatar answered Nov 03 '25 10:11

Alex Mamo