0
votes

Help me please. I am working with social network app. I want create PFObject "Group". Users can follow it. But only other participants can add other users as members.

As I understand I can develop following feature with PFRelation class. But tell me please, how can I develop feature with adding other users to group?User is protected class so I can't add PFRelation to another user. So only one way adding users to groups by another user is creation array of pointers?

Any thoughts? Thanks

1
There are two, distinct ideas: array of pointers and relation. For members of a group numbering in the 100k, the only reasonable choice is a relation. - danh
PFRelation is the way to go. Using an Array will make it so slow when making a query. - gagarwal
Thanks, guys. But could I add PFRelation from User1 to User2? PFUser is protected, so I can't add another user without his conformation right? + I can't understand how can I create query where user is participant - Roman
I found this blog.parse.com/2012/05/17/new-many-to-many. So I can do the same queries as with array. Nice - Roman
change my question for clearly understanding the problem - Roman

1 Answers

1
votes

So you want to create a many-to-many relationship between users and groups and only users that are already members of a given group can add a new user to this group right ?

If so here is how I would do it...

  1. Group creation

    // Create the group and add its creator as the sole group member
    PFUser * user = [PFUser currentUser];
    PFObject * group = [[PFObject alloc] initWithClassName:@"Group"];
    PFRelation * members = [group relationForKey:@"members"];
    [members addObject:user];
    
    // Set an ACL so that the group is visible but only the 
    PFACL * acl = [PFACL ACL];
    [acl setPublicReadAccess:true];
    [acl setWriteAccess:true forUser: user];
    group.ACL = cal
    
  2. Add a new group member

    PFUser * member = [PFUser currentUser];
    PFUser * candidate = ...; // not yet a member 
    PFObject * group = ...; // The group candidate wants to join
    PFRelation * members = [group relationForKey:@"members"];
    [members addObject:candidate];
    [group.ACL setWriteAccess:true forUser:candidate];
    

In step 2, member is a member of group and so has write access required to add a new user, candidate. After step 2, candidate is now a full member and has gained write access to the group.

However I have not tested this: - Does the relation "inherits" the ACL from the group ? Or anyone that can read the group, can access the relation and then add itself to the group ?

Also it seems hard to distinguish roles among members. I think that now any member could decide to delete the group...

You're probably better off enforcing the rules at application level.