That is how you check if some user is a friend of the current user.
1
2
3
4
5
Communities.isFriend(UserId.create("user_id"),{isFriend:Boolean->Log.d("Communities","User is your friend: $isFriend")},{error:GetSocialError->Log.d("Communities","Failed to check if friends: $error")})
1
2
3
4
5
6
letuserId=UserId.create(withId:"user1")Communities.isFriend(userId,success:{isFriendinprint("Current user and \(userId) are \(isFriend==true?"":"not") friends")},failure:{errorinprint("Error while checking friend status: \(error)")})
1
2
3
4
5
6
7
8
varuserId=UserId.Create("user1");Communities.IsFriend(userId,(result)=>{Debug.Log("`user` is friend? "+result);},(error)=>{Debug.Log("Failed to get friend status, error: "+error);});
1
2
3
4
varuserId=UserId.create('user-id');Communities.isFriend(userId)
.then((result)=>print('User is friend? $result'))
.catchError((error)=>print('Failed to check friend status, error: $error'));
1
2
3
4
5
6
7
constuserId=UserId.create('user-id');Communities.isFriend(userId).then((result)=>{console.log('User is friend? '+result);},(error)=>{console.log('Failed to check friend status, error: '+error.message);});
You can get the number of friends of the current user with the help of the following method.
1
2
3
4
5
Communities.getFriendsCount(FriendsQuery.ofUser(UserId.currentUser()),{friendsCount:Int->Log.d("Communities","Friends count: $friendsCount")},{error:GetSocialError->Log.d("Communities","Failed to check friends count: $error")})
1
2
3
4
5
6
letquery=FriendsQuery.ofUser(UserId.currentUser())Communities.friendsCount(query,success:{friendsCountinprint("Number of friends of current user: \(friendsCount)")},failure:{errorinprint("Error while receiving friends count: \(error)")})
1
2
3
4
5
6
7
8
varquery=FriendsQuery.OfUser(UserId.CurrentUser());Communities.GetFriendsCount(query,(result)=>{Debug.Log("Number of friends: "+result);},(error)=>{Debug.Log("Failed to get number of friends, error: "+error);});
1
2
3
4
varquery=FriendsQuery.ofUser(UserId.currentUser());Communities.getFriendsCount(query).then((result) {
print('Number of friends: $result');
}).catchError((error)=>print('Failed to get number of friends, error: $error'));
1
2
3
4
5
6
constquery=FriendsQuery.ofUser(UserId.currentUser());Communities.getFriendsCount(query).then((result)=>{console.log('Number of friends: '+result);},(error)=>{console.log('Failed to get number of friends, error: '+error);});
You can get the list of all friends of the current user page by page.
1
2
3
4
5
6
7
8
valquery=FriendsQuery.ofUser(UserId.currentUser())valpagingQuery=PagingQuery(query)Communities.getFriends(pagingQuery,{result:PagingResult<User>->valfriends=result.entriesLog.d("Communities","Friends: $friends")},{error:GetSocialError->Log.d("Communities","Failed to get friends: $error")})
1
2
3
4
5
6
7
8
9
letquery=FriendsQuery.ofUser(UserId.currentUser())letpagingQuery=FriendsPagingQuery(query)Communities.friends(pagingQuery,success:{responseinresponse.friends.forEach{print("[\($0.displayName)] is friend")}},failure:{errorinprint("Error while receiving friends: \(error)")})
1
2
3
4
5
6
7
8
9
10
11
varquery=FriendsQuery.OfUser(UserId.CurrentUser());varpagingQuery=newPagingQuery<FriendsQuery>(query);Communities.GetFriends(pagingQuery,(result)=>{result.Entries.ForEach(entry=>{Debug.Log(entry.DisplayName+" is a friend");});},(error)=>{Debug.Log("Failed to get list of friends, error: "+error);});
1
2
3
4
varquery=FriendsQuery.ofUser(UserId.currentUser());Communities.getFriends(PagingQuery(query))
.then((result) { result.entries.forEach((friend) { print(friend.displayName+' is a friend'); }); })
.catchError((error)=>print('Failed to list of friends, error: $error'));
1
2
3
4
5
6
7
8
9
constquery=FriendsQuery.ofUser(UserId.currentUser());Communities.getFriends(newPagingQuery(query)).then((result)=>{result.entries.forEach((friend)=>{console.log(friend.displayName+' is a friend');});},(error)=>{console.log('Failed to list of friends, error: '+error);});
When the user is building his social graph and creating connections with other users, GetSocial backend is finding the best possible options to make new friendship for your user. As a result, we make a list of users, which are not directly connected to the user but have mutual friends with him. That means that these users could be friends with your user in real life, but they have not met in your game yet. With Suggested Friends functionality you can make building user’s social graph process much faster. Use it as described below:
1
2
3
4
5
6
7
valpagingQuery=SimplePagingQuery.simple(20)Communities.getSuggestedFriends(pagingQuery,{result:PagingResult<SuggestedFriend>->valfriends=result.entriesLog.d("Communities","Suggested friends: $friends")},{error:GetSocialError->Log.d("Communities","Failed to get suggested friends: $error")})
1
2
3
4
5
6
7
8
letpagingQuery=PagingQuery()Communities.suggestedFriends(pagingQuery,success:{responseinresponse.suggestedFriends.forEach{print("[\($0.displayName)] is a suggested friend")}},failure:{errorinprint("Error while receiving suggested friends: \(error)")})
1
2
3
4
5
6
7
8
9
10
varpagingQuery=newSimplePagingQuery();Communities.GetSuggestedFriends(pagingQuery,(result)=>{result.Entries.ForEach(entry=>{Debug.Log(entry.DisplayName+" is a suggested friend");});},(error)=>{Debug.Log("Failed to get suggested friends, error: "+error);});