0

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

6
  • 2
    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. Commented Mar 6, 2015 at 18:39
  • PFRelation is the way to go. Using an Array will make it so slow when making a query. Commented Mar 6, 2015 at 18:47
  • 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 Commented Mar 6, 2015 at 18:49
  • I found this blog.parse.com/2012/05/17/new-many-to-many. So I can do the same queries as with array. Nice Commented Mar 6, 2015 at 18:57
  • change my question for clearly understanding the problem Commented Mar 8, 2015 at 5:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.