Creating and joinin...
 
Notifications
Clear all

Creating and joining user groups

19 Posts
3 Users
0 Reactions
2,019 Views
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

Hello.

I'm trying to figure out the user group feature. But before I go ahead and do it wrong, I'd like to clarify a few things:

1) When I call one of the two UserGroup.Load functions, I'll get all the user groups that that particular user (identified by either ID or username) is either leader or member of. Correct?

2) How do I create a new group? Do I just call the constructor? If so, how do I upload it to the server?

3) All the join functions seem to take a list of users. Is the idea that the group leader adds everyone else to the group? We'd like to do a similar thing as with friend requests: You request membership in a group and then the group leader either accepts or refuses.

Thank you in advance for anything you can tell us.

 
Posted : 19/09/2015 2:08 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

1) When I call one of the two UserGroup.Load functions, I'll get all the user groups that that particular user (identified by either ID or username) is either leader or member of.

Correct

2) How do I create a new group? Do I just call the constructor? If so, how do I upload it to the server?

Yes, instantiate a new object of class UserGroup, set the name and users and call Save (the logged user is the owner so you shouldn't need to add to the users list). For the users you can create an array of User objects with only username set, but don't mix objects with username and with id, you should pass either a list with id or a list with username.

3) All the join functions seem to take a list of users. Is the idea that the group leader adds everyone else to the group? We'd like to do a similar thing as with friend requests: You request membership in a group and then the group leader either accepts or refuses.

The idea is to allow the developer to choose how they want to join/leave the groups. The membership request is not implemented but you could use the Mail feature as trick and create special messages for that (that you will filter in the player's inbox if you use in-game messaging). In the body of the message you would add your identifiable code to handle requests, accepts and refuses; to easily encode useful data you may take benefits of using the JSON functions: yourHashtable.toJson(), yourArrayList.toJson(), yourJsonString.hashtableFromJson(), yourJsonString.arraylistFromJson()

If you are experienced in PHP and MySQL programming (or have a web developer) then the alternative could be to create an add-on to handle the requests if a user wants to join a group (your add-on would use its own table on database for requests sent, accepted and refused with IdGroup, IdAccount and State, for the PHP class of the table you can take a look at the core CB_* classes that inherits from DataClass and do similarly).

You can learn more about how to create an add-on at here.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 19/09/2015 2:34 am
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

Thanks for your clarification!

Though about point 3: If we use the messaging system for this, the player requesting membership would have to know to send the request to the group leader instead of the group itself, right? As in, if we have a field for the recipient of the request, the player would have to type in the leader's name instead of the group name, which would be doable but not perfect.

Or, looking at it more closely, there seems to be a "Mail.SendMessageToGroup" function, but it takes the group ID, not its name, so if you just know you want to join the group called "the cool group", there seems to be no way to get the ID.

 
Posted : 19/09/2015 6:01 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Yes unfortunately we haven't currently a reference to the owner of the group, I will add it in a later version, so your only option is SendMessageToGroup. And yes you must have the ID, and you for sure have it since you already loaded them from UserGroup.Load, the group name is not unique so it's not possible to load by name (groups may be used in an application to work as Facebook contact lists for example, so I didn't block with unique names).

In your case I would use something like the following:

// Send request to join
UserGroup requestGroup;
// ... you have loaded the groups so should have set requestGroup
Hashtable request = new Hashtable();
request.Add("GroupRequest"requestGroup.id.ToString());
string messageText = request.toJson();

// Owner of the group reads it, the others should ignore and delete
Mail mail// you have loaded the mail
request = messageText.hashtableFromJson();
if (request != null)
{
    if (request.ContainsKey("GroupRequest"))
    {
        long id = long.TryParse(request["GroupRequest"].ToString());
        UserGroup.Load(CombuManager.localUser.idLong, (UserGroup[] groupsstring error) => {
            foreach (UserGroup group in groups)
            {
                if (group.id == id)
                {
                    // if we accept
                    group.Join(new long[] {mail.fromUser.idLong}, (bool successstring errorJoin) => {
                        // ..
                    });
                    // if we decline you can send a private message (not to groupusing a similar logic
                    mail.Delete(null);
                    break;
                }
            }
        });
    }
}

 

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 19/09/2015 10:03 pm
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

OK, thanks.

So if I read that correctly, the person requesting a group would still have to be told the ID of the group via some manual means. (You say you already have the ID from UserGroup.Load, but I'm assuming you meant it's known on the group leader's side via that. The UserGroup.Load wouldn't return a group you haven't already joined, right?)

 
Posted : 20/09/2015 3:36 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

I'm currently improving the UserGroup features, should be able to release 2.1.1 next week with the following enhancements:

  • UserGroup will have new properties: idOwner (long), owner (User)
  • UserGroup.Load currently retrieves only the groups belonged to a user so the parameter idUser will be renamed to idOwner and username renamed to usernameOwner, also new parameters will be added: idMember (long), usernameMember (string)
  • UserGroup.Load will not require owner/member to be specified, so you will be able to load all groups (and from them their owners)

...and eventually more.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 20/09/2015 5:17 pm
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

Thanks for addressing this in the new version!

However, it occurs to me that if we want the players to be able to join groups by name, we're going to have to load the entire list of user groups. Which, if we become popular, might be a pretty long list, and the page-by-page system doesn't help much (to make sure whether a group exists or not, we'll have to load every group anyway, unless they're somehow cleverly ordered by name).

We could really use a simple UserGroup.Load(string groupName) method. It would be fine if it returned all duplicates with that name. We could then create our own client-side logic that prevents people from creating duplicates. Of in fact, in our case it would be enough to repurpose the Load(ownerName) to Load(groupName), as long as we can still use LoadMembership the normal way. Would we be able to do that on the server's end ourselves? Earlier, we already repurposed the recovery email feature to take the user's email instead of username as input.

 
Posted : 01/10/2015 3:55 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

I cannot force apps to have the same name for players' groups, for example an app may want to allow private groups (created by players for themselves, e.g. "Family", "Friends", etc) and public groups.

I really don't understand what's your issue, usually in any app/game a player click JOIN to join a group so you HAVE the Id (else from what is coming the group list?).

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 01/10/2015 4:06 pm
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

Thanks for the response.

We ended up doing it the way you intended (the group owner adds the other members to the group). The players can then leave if they want, or the owner can remove them from the group. However, we have another problem with this approach: If a player leaves a group, they disappear from the member listing of that group as expected. But when I call UserGroup.LoadMembership on that player again, I still get that group they used to be a member of. (Edit: It's also possible that we simply always get all user groups instead of the ones the player is a member of.)

Just to clarify on what our issue was before, though: We didn't want to list all the user groups so a player can click "join" on them - we expect hundreds of groups. So we wanted to have the player enter the name of the group they want to join. The only way to check the name against all groups would be to load all the hundreds of groups from the server, because there's no option to load a group by name. But this is now moot as we decided to do it the way described above.

As always, I appreciate all the help you can give.

 
Posted : 02/10/2015 8:39 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Sorry I'm not having this issue during tests, may be you're calling LoadMembership or Leave on the wrong user, or before it's updated, don't know your code but I tried with a unit test that searched for group, joined, left and called LoadMembership as expected.

Anyway for the next update I added a search by name that could help you with your logic, going to send you a pre-release by PM since you're working on this type of app.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 03/10/2015 11:18 pm
(@gecko64)
Posts: 82
Estimable Member
 

Actually, what's happening is what Tommi said in parenthesis: ALL groups are listed for all users, all the time. Someone else creates a group, and doesn't even add any players to it, and it shows up in my group list. So it's nothing to do with the Leave action. How do we debug that? 

 
Posted : 05/10/2015 4:31 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

gecko64 said
Actually, what's happening is what Tommi said in parenthesis: ALL groups are listed for all users, all the time. Someone else creates a group, and doesn't even add any players to it, and it shows up in my group list. So it's nothing to do with the Leave action. How do we debug that? 

Calling what function? I'm trying to pass CombuManager.localUser.idLong to User.Load and User.LoadMembership and they return 0 if the local user is not in a group.

Anyway I uploaded a new version 2.1.3 on this website to test, please download and try it as it has some bug fixes.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 05/10/2015 7:22 pm
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

We are calling the UserGroup.LoadMembership(CombuManager.localUser.userName, callback). It returns all the groups, even if the player with the given username is not member of any group at all. (I assume you didn't mean "User.LoadMembership" as that function doesn't exist in the docs.)

 
Posted : 07/10/2015 2:33 pm
(@tommih)
Posts: 44
Trusted Member
Topic starter
 

Hello, and thanks for the response you gave David yesterday!

I did some testing and it turns out it works as long as I explicitly give the types for the parameters in the callback function. So, this works:

UserGroup.LoadMembership(CombuManager.localUser.userName, (UserGroup[] memberGroupstring errorMember) => {

but this doesn't:

UserGroup.LoadMembership(CombuManager.localUser.idLong, (memberGroup, errorMember) => {

I have no idea how this could be possible, but maybe I don't know everything there is to know about lambda functions..

 
Posted : 08/10/2015 5:03 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Well, I receive "0" with both syntax without any issue in Unity editor with platform 'desktop standalone'.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 08/10/2015 6:07 pm
Page 1 / 2
Share: