Friends

Friends are a great way to build a social community. Users can add other users to their list of friends, see who is online or when they were last online, chat together in real-time, and interact together in gameplay or collaboration.

Each user builds up a list of friends by who they know already from their social networks, friend requests they send, requests they receive, and who the server recommends they should know. This information is stored in a social graph within the system as a powerful way to interact with other users. Much like how Twitter or Facebook work.

Any social community must be maintained carefully to prevent spam or abuse. To help with this problem it’s also possible for a user to block users they no longer want to communicate with and for the server to ban a user via server-side code to completely disable an account.

Nakama is a common Japanese word that directly translates to friend or comrade. Some believe the word means “people who are considered closer than family”, though that is not a part of the official definition. We feel it expresses the kind of social communities we want developers to build into their games and apps!

Add friends

A user can add one or more friends by that user’s ID or username. The user added will not be marked as a friend in the list until they’ve confirmed the friend request. The user who receives the request can confirm it by adding the user back.

When a friend request is sent or the user is added an in-app notification will be sent. See the in-app notification section for more info.

Client

<br>1<br>2<br>3<br> javascript<br>var ids = ["user-id1", "user-id2"];<br>var usernames = ["username1"];<br>await client.addFriends(session, ids, usernames);<br>

Import friends

A user who registers or links their account with Facebook, Steam, or another social network can select to have friends from that network imported into their friend list.

Alternatively, you can enable users to perform this import at any time via Nakama’s support for on-demand importing of friends.

Facebook

Import a user’s Facebook friends into your app at any time, and optionally reset their current friends list when doing so.

Client

<br>1<br>2<br>3<br> javascript<br>const token = "<facebookAuthToken>";<br>const reset = true;<br>await client.importFacebookFriends(token, reset);<br>

List friends

You can list all of a user’s friends, blocked users, friend requests received (invited), and invites they’ve sent. These statuses are returned together as part of the friend list which makes it easy to display in a UI. A single friends listing will return a page of up to 1000 friends. Pass the returned cursor to subsequent list calls to retrieve more friend pages.

Client

<br>1<br>2<br> javascript<br>const friends = await client.listFriends(session);<br>console.info("Successfully retrieved friend list:", friends);<br>

List friends of friends

To list friends of friends for this user. A maximum of 100 results per request is allowed. An optional cursor can be supplied, don’t set to start fetching from the beginning.

Client

<br>1<br>2<br>3<br> javascript<br>var limit = 10;<br>const friends = await client.listFriendsOfFriends(session, limit);<br>

Remove friends

A user can remove a friend, reject a received invite, cancel a friend request sent, or unblock a user. If a user is unblocked they are removed from the friend list entirely. To re-add them each user must add the other again.

Client

<br>1<br>2<br>3<br> javascript<br>var ids = ["user-id1", "user-id2"];<br>var usernames = ["username1"];<br>await client.deleteFriends(session, ids, usernames);<br>

Block a friend

You can stop a user from using 1-on-1 chat or other social features with a user if you block them. The user who wants to block should send the message. They can be unblocked later with a Friend Remove message.

Client

<br>1<br>2<br>3<br> javascript<br>var ids = ["user-id1", "user-id2"];<br>var usernames = ["username1"];<br>await client.blockFriends(session, ids, usernames);<br>

Additional Information