0

I am building a social network application using parse which have follow/unfollow feature.

I have two tables: Users and Follow table.

Users table have user related data and Follow table have two fields: followerId and followedId.

I have a list of searched users. So, corresponding to each user i just want to get from query that whether i am following him/her or not. So, how to run query inside a loop?

Any help will be deeply appreciated.

Thanks.

Ankit Kamboj
  • 141
  • 2
  • 13
  • You can achieve this by fetching all user list in loop. When you found all the searched users then you can run the query in the second loop. – Mamta Kaundal Mar 28 '17 at 06:08

1 Answers1

0

For get follower

ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followedId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
    public void done( List<ParseObject> MyList, ParseException e) {

        if (e == null) {
            // Get your follower user list

        }else{
            //error
        }

For get following

ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followerId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
    public void done( List<ParseObject> MyList, ParseException e) {

        if (e == null) {
            // Get your following user list

        }else{
            //error
        }

Then after call user list query in ParseUser table and get all the user. Thanks

Jd Prajapati
  • 1,953
  • 13
  • 24
  • 1
    I have to implement this functionality in search screen. e.g. I am searching a user An. An has multiple instances like Ankit, Anuj. So, based on that i want to fetch userId of first user and then send it to other query to find follow/unfollow. – Ankit Kamboj Mar 27 '17 at 05:27
  • So, How to implement this functionality in for loop? – Ankit Kamboj Mar 27 '17 at 05:28
  • why you are doing like this way...its taking more load on call search.. its better you can first get user list then after search locally.. 1) Get your follower user and add search locally 2) Get your following user and add search locally – Jd Prajapati Mar 27 '17 at 05:37
  • 1
    I have to search users and then shows them in list with follow/following button. So, for this, i have to search users, then select a userId then send it to other query. – Ankit Kamboj Mar 27 '17 at 05:44
  • this is for the add to following....what you want? after search user you want to add following entry in follow table? – Jd Prajapati Mar 27 '17 at 06:20
  • Yes. If i already following someone, then it should show following button, else it should show follow button. Also, i want to follow/unfollow user from these buttons. – Ankit Kamboj Mar 27 '17 at 06:23
  • for follow/unfollow you need first fetch all the following users then after you can manage – Jd Prajapati Mar 27 '17 at 06:40
  • 1
    Please, paste here your current code. We can help you to figure out the best way to improve it. – Davi Macêdo May 03 '17 at 18:43