# Social

With the social system, users can find their friends and start communication with them like sending real-time messages and creating games together. Users have their own friend list, and they can see others status

# Search User

User can search others by having their username. to do this, we can use SearchFriend

    client.Friend.SearchFriend("jupiter", (searchRes) =>{});

As a result, if that username exists we get that user userId, for sending request we need that parameter.

# Send Request

For sending friend request we can use RequestFriend. for doing this we need get user id from previous step like searchRes.Data["user_id"]

     client.Friend.RequestFriend(searchRes.Data["user_id"], (res2) =>{});

# Accept Friend Request

The User can accept or reject their friend requests. After the user is logged in, they can see the request list anytime, which they can accept or reject them. to get all requests we can do like this

    var deviceId = SystemInfo.deviceUniqueIdentifier;
    client.AuthenticateDeviceId(deviceId, (user, result) =>{

         if (user.FriendRequest != null)
            {
                foreach (JSONNode req in user.FriendRequest)
                {
                    client.Friend.AcceptFriend(req["user_id"], req["username"], (res2) =>{});
                }
            }
    });

# Reject Friend Request

To reject a user request we can use RejectFriend method

    var deviceId = SystemInfo.deviceUniqueIdentifier;
    client.AuthenticateDeviceId(deviceId, (user, result) =>{

        if (user.FriendRequest != null)
        {
            foreach (JSONNode req in user.FriendRequest)
            {
                    client.Friend.RejectFriend(req["user_id"], (res3) =>{});
            }
        }
    });

# Remove Friend

User can remove friends from their friend list by using RemoveFriend method

    client.Friend.RemoveFriend("friendUserId", (res4) =>{});

# Sending Message

User can send message to a friend or to the group

# Send Message To Friend

For sending a message to a friend you need userId for that friend. to send a message we can use SendMessageToId method

    client.Communication.SendMessageToId(friendUserId, "hi my friend", (res) => {});

# Send Message To Group

For sending a message to a group you need playmateId which we can get that id in matchmaking part. to sending a message we can use SendMessageToGroup method

    client.Communication.SendMessageToGroup(playmateId, "send message to playmates",(res)=> {});

# Get Messages

To receive messages you can use OnMessage event

    client.Communication.OnMessage = (mes) =>
    {
        Debug.Log(mes.Text);
        Debug.Log(mes.SenderId);
        Debug.Log(mes.SenderUsername);
        Debug.Log(mes.SenderSocketId);

        if (mes.Type == Message.ToId)
        {
            Debug.Log(mes.Text);
        }
        if (mes.Type == Message.ToGroup)
        {
            Debug.Log(mes.Text);
        }
    };

# Friend List

Users can reach to their friend list as below

    var deviceId = SystemInfo.deviceUniqueIdentifier;
    client.AuthenticateDeviceId(deviceId, (user, result) =>{

         if (user.FriendList != null)
            {
                foreach (JSONNode req in user.FriendList)
                {
                    Debug.Log(req["friend_id"]);
                    Debug.Log(req["friend_username"]);
                    Debug.Log(req["friend_socketId"]);
                    Debug.Log(req["friend_status"]);
                }
            }
    });