Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create groups of ParseUsers using Parse.com?

Currently I'm using Parse.com in order to create multiple ParseUsers. This works perfectly and each user can login individually. However from here I want to expand my app to allow Users to create groups of users and therefore have data that is only relevant and shared between these Users. This will mean that when the User logs in, they can see a List of the groups they are members of and from there can share data simply just to those users of that individual group. What would be the best way to tackle this and does anybody have any examples or tutorials that I could follow in order to understand this concept?

I've considered creating a Group class and then making this store User's IDs in an array and then allow each User to store an array of the Group IDs that they're currently members of. I'm just not really sure how to broach this issue.

Thanks in advance!

like image 423
edwoollard Avatar asked Feb 03 '14 20:02

edwoollard


People also ask

What is Parse server used for?

The sole purpose of Parse was to demystify the process of backend development. Launched in February 2016, Parse Server is an open source version of Parse (MBaaS platform) which was originally developed by Parse Inc. It can be deployed to any infrastructure that can run node. js.

What database does Parse use?

Parse Server uses MongoDB or PostgreSQL as a database. You can deploy and run Parse Server on your own infrastructure. You can develop and test your app locally using Node.

What is Parse user?

A Parse. User object is a local representation of a user persisted to the Parse cloud. This class is a subclass of a Parse. Object, and retains the same functionality of a Parse. Object, but also extends it with various user specific methods, like authentication, signing up, and validation of uniqueness.


1 Answers

I ended up doing as shown below:

 ParseQuery<ParseRole> query = ParseRole.getQuery();
 Intent intent = getActivity().getIntent();
 String groupId = intent.getStringExtra("groupId");
 query.whereEqualTo("objectId", groupId);
 groupUsers = new ArrayList<String>();
 query.findInBackground(new FindCallback<ParseRole>() {
     @Override
     public void done(List<ParseRole> objects, ParseException e) {
        if(e == null) {
            for(ParseRole role : objects) {
                ParseRelation<ParseUser> usersRelation = role.getRelation("users");
                ParseQuery<ParseUser> usersQuery = usersRelation.getQuery();
                usersQuery.findInBackground(new FindCallback<ParseUser>() {
                    @Override
                    public void done(List<ParseUser> objects, ParseException e) {
                        for(ParseUser user : objects) {
                            groupUsers.add(user.getUsername());
                        }
                    }           
                });
            }
         } else {
             Toast.makeText(getActivity(), "ERROR", Toast.LENGTH_SHORT).show();
         }              
      }                  
 });       

I passed in the group ID from the Intent that sent me to that Fragment that I was checking and then populated my ListView with the list that I've returned from the query on the Parse database with the specific group ID. I hope this helps anyone else who had the same issue as me. Good luck!

like image 139
edwoollard Avatar answered Sep 26 '22 02:09

edwoollard