Skip to main content
Version: v3

Follow Mode

Before continuing, make sure you have finished initializing the SDK.

Responding to Friend Status Changes

With the Friends module, the client can listen to the status changes of the player’s friends and display them to the player in real-time. You’ll need to register an instance for listening to friend status changes before calling the interface for getting the player online. By doing this, the player will be able to receive notifications after they get online:

TDSFollows.FriendStatusChangedDelegate = new TDSFriendStatusChangedDelegate {
// The current player got online (connection established)
OnConnected = () => {},
// Connection lost; the SDK will try to reconnect automatically
OnDisconnected = () => {},
// Connection error
OnConnectionError = (code, message) => {},
};

To stop listening:

TDSFollows.FriendStatusChangedDelegate = null;

Getting the Player Online

After the player logs in, you need to call this interface to establish a persistent connection between the client and the cloud. Once the persistent connection is established, if there is an interruption to the internet connection, the SDK will automatically reconnect once the connection is restored.

await TDSFollows.Online();

Getting the Player Offline

After the player logs out, you need to call this interface to disconnect the client from the cloud.

await TDSFollows.Offline();

Searching for Friends by Nickname

A player can search for friends by nickname without knowing their objectIds. For example, to search for friends with Tarara as their nickname:

ReadOnlyCollection<TDSFriendInfo> friendInfos = await TDSFollows.SearchUserByName("Tarara");
foreach (TDSFriendInfo info in friendInfos) {
// Player data
TDSUser user = info.User;
// Rich presence data; continue reading for more information
Dictionary<string, string> richPresence = RichPresence;
// Whether the friend is online
bool online = info.Online;
}

Notice that in order to use this function, the nickname field has to be set on the built-in account system. See TDS Authentication Guide for more information.

Friend Code

Each logged-in player has a friend code that can be shared with other players so these players can quickly add the current player as their friend.

You can get the friend code of a TDSUser from its shortId field:

// currentUser is a logged in TDSUser
string shortId = currentUser["shortId"];

To search for a player with their friend code:

TDSFriendInfo friendInfo = await TDSFollows.SearchUserByShortCode(shortId);

Searching for Friends With objectId

Besides using nicknames and friend codes, a player can also search for friends with their objectIds.

For example, to search for the friend with 5b0b97cf06f4fd0abc0abe35 as their objectId:

TDSFriendInfo friendInfo = await TDSFollows.SearchUserById("5b0b97cf06f4fd0abc0abe35");

Rich Presence

Rich presence can be used to display the player’s status information like their online status, current hero, and current game mode.

After adding configurations for rich presence on the Developer Center, you can set the content of a player’s rich presence according to the configured fields for rich presence:

await TDSFollows.SetRichPresence("score", "60");

Here score is a rich presence field configured on the Developer Center. There are two types available for each rich presence field:

  • variable: The value is a string. In the code example above, with score configured to be a variable on the Developer Center, the client sets the value of this field to be 60 when updating the rich presence data. The cloud will accordingly return "score": "60" to the client as the rich presence data. You need to handle the localization-related logic yourself so that the player can eventually see something like “Score: 60”.

  • token: The value is a string starting with #. In the example below, the type of display is token, and the client sets the value of this field to be #matching when updating the rich presence data. The cloud will handle the conversion of this value to a localized string and return the result like "display": "Matching" to the client. Notice that if the cloud fails to convert the value, an empty string like "display": " " will be returned.

To set multiple fields at once:

Dictionary<string, string> info = new Dictionary<string, string>();
info.Add("score", "60");
info.Add("display", "#matching");
await TDSFollows.SetRichPresences(info);

You can configure at most 20 rich presence fields on the Developer Center. The key of each field should be no longer than 128 bytes and the value of each field should be no longer than 256 bytes.

You can use the following interface to clear a rich presence field for the current player:

TDSFollows.ClearRichPresence("score");

You can also clear multiple rich presence fields at once:

IEnumerable<string> keys = new string[] {"score", "display"}
await TDSFollows.ClearRichPresences(keys);

The interfaces for setting and clearing rich presence data can each be called at most once every 30 seconds.

There are some REST API interfaces related to rich presence. You can write your own scripts to perform administrative operations on the server side by interacting with these interfaces.

Following

A player can follow other players by entering their friend codes.

await TDSFollows.FollowByShortCode(shortId);

Additional properties can be specified when following other players. For example, to put the other player into the coworkers group:

Dictionary<string, object> attrs = new Dictionary<string, object> {
{ "group", "coworkers" }
};
await TDSFollows.FollowByShortCode(shortId);

A player can also follow a TDSUser with its objectId. For example, assuming Tarara’s objectId is 5b0b97cf06f4fd0abc0abe35, the current player can follow Tarara with the following code:

await TDSFollows.Follow("5b0b97cf06f4fd0abc0abe35");

Additional properties can be specified as well when following other players with objectId:

Dictionary<string, object> attrs = new Dictionary<string, object> {
{ "group", "coworkers" }
};
await TDSFollows.Follow("5b0b97cf06f4fd0abc0abe35");

Notice that a player can follow at most 5000 other players.

Unfollowing

A player can unfollow other players with their objectIds or friend codes. For example, after following Tarara, the current player changes their mind and doesn’t want to follow Tarara anymore:

await TDSFollows.UnFollow("5b0b97cf06f4fd0abc0abe35");

await TDSFollows.UnFollowByShortCode(shortIdOfTarara);

Blocklist

A player can block other players so they won’t be able to follow the current player anymore. By blocking a player, the existing connections between the current player and the target player will be removed. Similar to following and unfollowing, the player can block other players with their objectIds or friend codes. Assuming Tarara’s objectId is 5b0b97cf06f4fd0abc0abe35, to block Tarara:

await TDSFollows.Block("5b0b97cf06f4fd0abc0abe35");

await TDSFollows.BlockByShortCode(shortIdOfTarara);

A player can remove a user from their blocklist at any time:

await TDSFollows.Unblock("5b0b97cf06f4fd0abc0abe35");

await TDSFollows.UnblockByShortCode(shortIdOfTarara);

If there have been any connections between the current player and a target player before the current player blocks the target player, these connections will not be re-established automatically if the current player unblocks the target player.

To retrieve the current player’s blocklist:

FriendResult result = await TDSFollows.QueryBlockList(cursor, limit, sortCondition);

Notice that:

  • A player can block at most 100 other players.
  • Once Player A blocks Player B, not only Player B cannot follow Player A, Player A cannot follow Player B as well. If Player A has followed Player B or Player B has followed Player A, once Player A blocks Player B, they won’t be following each other anymore.

Retrieving Mutual Follower List

There is an interface for players to retrieve their mutual followers. This interface returns not only the mutual follower list but also a cursor. You can implement pagination by specifying the cursor and the number of players returned. The players in the result can be sorted according to their online status (those who are online will show up at the beginning).

// First query
string cursor = null;
// Defaults to 50; no larger than 500
int limit = 50;
// Sort by online status
SortCondition sortCondition = SortCondition.OnlineCondition
FriendResult result = await TDSFollows.QueryMutualList(cursor, limit, sortCondition);

ReadOnlyCollection<TDSFriendInfo> friendInfos = result.FriendList;
foreach (TDSFriendInfo info in friendInfos) {
// Player data
TDSUser user = info.User;
// Rich presence data
Dictionary<string, string> richPresence = info.RichPresence;
// Whether the player is online
bool online = info.Online;
}

// Pagination
string cursor = result.Cursor;
FriendResult more = await TDSFollows.QueryMutualList(cursor, limit, sortCondition);

Notice that to make it possible for the server to sort players by online status, you have to call the corresponding interfaces when a player gets online and offline. Otherwise, the server won’t be able to know the online statuses of the players and won’t be able to sort them by online status.

Retrieving Followees

Similarly, a player can retrieve the list of players they are following. The interface for this function is similar to that for retrieving mutual followers and the players in the result can be sorted by online status as well:

FriendResult result = await TDSFollows.QueryFolloweeList(cursor, limit, sortCondition);

Retrieving Followers

A player can also retrieve the list of players who are following them. The interface for this function is similar to those for retrieving mutual followers and followees, but it doesn’t support sorting the players in the result by online status:

FriendResult result = await TDSFollows.QueryFollowerList(cursor, limit, sortCondition);

If you specified to sort the result by online status, the cloud will ignore this condition and return the unsorted result.

Landing Page

A landing page has to be deployed before you use link sharing. The landing page can be deployed on Cloud Engine or any other server that can host a static page. If you plan to use Cloud Engine, keep in mind that the free instances provided by Cloud Engine come with auto-hibernation. Please consider purchasing standard instances.

We provide an [open-source demo landing page] for you to use. You can build, deploy, and use it with your own configurations. Notice that the format of the GAME_ANDROID_LINK environment variable of the demo is scheme://host/path. The values of host and path should be consistent with those written in the AndroidManifest.xml of your Android project.

For example, if the AndroidManifest.xml of your project contains the following configurations:

<activity
android:name="com.tapsdk.friends.TDSFriendsRouterPageActivity"
android:allowTaskReparenting="true"
android:configChanges="keyboardHidden|orientation"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="nosensor"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="APP_ID"
android:path="/friends"
android:scheme="tapsdk" />
<!-- The scheme cannot contain capital letters or underscores <a href="[scheme]://[host]/[path]?[query]">Launch the App</a> -->
</intent-filter>
</activity>

The value of GAME_ANDROID_LINK in your landing page should be tapsdk://APP_ID/friends.

The address of the landing page should be configured in the client:

TDSFollows.SetShareLink("https://please-replace-with-your-domain.example.com");

If the landing page is hosted on Cloud Engine, the address will be https://YOUR_CLOUD_ENGINE_CUSTOM_DOMAIN.

After the landing page has been deployed and the address has been configured in the client, you can call the following interface to generate invitation links:

string inviteUrl = await TDSFollows.GenerateFriendInvitationLink();

The default username in the link will be the nickname of the player. Therefore, you might want to make sure that you have set the nicknames of the users in the built-in account system. See TDS Authentication Guide for more information. To use other names, specify them when calling the above interface. You can also provide other parameters that can be attached to the URL of the invitation link as query parameters. For example, if the player named Tarara wants to use “Taro” as their name and attach a ref=taptap parameter, you can do this:

Dictionary<string, object> parameters = new Dictionary<string, object> {
{ "ref", "taptap" }
};
string inviteUrl = await TDSFollows.GenerateFriendInvitationLink("Taro", parameters);

After the player opens the game with an invitation link, you need to call the following interface to have the player follow the target player.

public class DeepLinkManager : MonoBehaviour
{
// Other things to do
private async void onDeepLinkActivated(string url) {
await TDSFollows.HandleFriendInvitationLink(url);
}
}

You can also parse the link with the following interface provided by the SDK and get the player’s objectId and name as well as other parameters. You can perform your custom logic with them.

public class DeepLinkManager : MonoBehaviour
{
// Other things to do
private async void onDeepLinkActivated(string url) {
TDSFriendLinkInfo invitation = TDSFollows.ParseFriendInvitationLink(url);
string userObjectId = invitation.Identity;
string name = invitation.RoleName;
Dictionary<string, string> parameters = invitation.Queries;
await TDSFollows.Follow(userObjectId);
}
}

Notice that:

The demo project uses the Friend mode by default. Please change INVITE_TYPE to follow to switch to the Follow mode.