Class SFS2X.Entities.SFSBuddy

The representation of a buddy in the current user's buddy list.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Entities.SFSBuddy(id, name, isBlocked, isTemp)
Creates a new SFSBuddy instance.

Field Summary

Method Summary

Class Detail

SFS2X.Entities.SFSBuddy(id, name, isBlocked, isTemp)
Creates a new SFSBuddy instance.

A buddy is marked out by the following characteristics:
- Nickname: a buddy can have an optional nickname, which differs from the username used during the login process.
- Online/offline state: users can be online or offline as buddies in the Buddy List system. By default a buddy is online every time he joins a Zone, but the user can also switch the state to offline at runtime, and disappear from other user's buddy lists. This state is persistent and it is based on a reserved Buddy Variable.
- Custom state: each user can have a typical IM state such as "Available", "Away", "Occupied", etc. The state can be selected among the custom ones defined in the Zone configuration, which can be changed or enriched at any time. This state is persistent and it is based on a reserved Buddy Variable.
- Blocked buddy: buddies that are blocked in a user's buddy list won't be able to send messages to that user; also they won't be able to see if the user is online or offline in the Buddy List system.
- Temporary buddy: a temporary buddy is added to the current user's buddy list whenever another user adds him to his own buddy list. In this way users can "see" each other and exchange messages. If the current user doesn't add that temporary buddy to his buddy list voluntarily, that buddy won't be persisted and will be lost upon disconnection.
- Variables: Buddy Variables enable each user to show (and send updates on) specific custom informations to each user to whom he is a buddy. For example one could send realtime updates on his last activity, or post the title of the song he's listening right now, or scores, rankings and whatnot.

NOTE: developers never istantiate a SFSBuddy manually: this is done by the SmartFoxServer 2X API internally. Creating an instance and passing it to the API can disrupt its functioning.

Parameters:
{Number} id
The buddy id.
{String} name
The buddy name.
{Boolean} isBlocked Optional, Default: false
If true, the buddy is blocked by the current user.
{Boolean} isTemp Optional, Default: false
If true, the buddy is just temporary in the current user's buddy list.
See also:
SFS2X.SmartFox#buddyManager
SFS2X.Entities.Variables.SFSBuddyVariable

Field Detail

{Number} id
Indicates the id of this buddy. This is equal to the id assigned by SmartFoxServer to the corresponding user.

NOTE: the id is unique and it is generated by the server when the buddy instance is created. Setting it manually has no effect on the server and can disrupt the API functioning.

See also:
SFS2X.Entities.SFSUser#id
{String} name
Indicates the name of this buddy. This is equal to the name of the corresponding user.

NOTE: setting the name property manually has no effect on the server and can disrupt the API functioning.

See also:
SFS2X.Entities.SFSUser#name

Method Detail

  • {Boolean} containsVariable(varName)
    Indicates whether this user has the specified Buddy Variable set or not.
    Parameters:
    {String} varName
    The name of the Buddy Variable whose existance must be checked.
    Returns:
    {Boolean} true if a Buddy Variable with the passed name is set for this buddy.
  • {String} getNickName()
    Returns the nickname of this buddy. If the nickname is not set, null is returned.
    Returns:
    {String} The nickname of the buddy.
  • getOfflineVariables()
    Retrieves the list of persistent Buddy Variables for this buddy.
    Returns:
    An array of SFSBuddyVariable objects.
    See also:
    SFS2X.Entities.Variables.SFSBuddyVariable#isOffline
  • getOnlineVariables()
    Retrieves the list of non-persistent Buddy Variables for this buddy.
    Returns:
    An array of SFSBuddyVariable objects.
    See also:
    SFS2X.Entities.Variables.SFSBuddyVariable#isOffline
  • {String} getState()
    Returns the custom state of this buddy. Examples of custom states are "Available", "Busy", "Be right back", etc. If the custom state is not set, null is returned.

    The list of available custom states is returned by the BuddyManager.getBuddyStates method.

    Returns:
    {String} The custom state of the buddy.
    See also:
    SFS2X.Managers.BuddyManager#getBuddyStates
  • {SFSBuddyVariable} getVariable(varName)
    Retrieves a Buddy Variable from its name.
    Parameters:
    {String} varName
    The name of the Buddy Variable to be retrieved.
    Returns:
    {SFSBuddyVariable} The object representing the Buddy Variable, or null if no Buddy Variable with the passed name is associated to this buddy.
    See also:
    #getVariables
    SFS2X.Entities.Variables.SFSBuddyVariable
    SFS2X.Requests.BuddyList.SetBuddyVariablesRequest
  • {Array} getVariables()
    Retrieves all the Buddy Variables of this user.
    Returns:
    {Array} The list of SFSBuddyVariable objects associated to the buddy.
    See also:
    SFS2X.Entities.Variables.SFSBuddyVariable
    #getVariable
  • {Boolean} isBlocked()
    Indicates whether this buddy is blocked in the current user's buddy list or not. A buddy can be blocked by means of a BlockBuddyRequest request.
    Returns:
    {Boolean} true if the buddy is blocked.
    See also:
    SFS2X.Requests.BuddyList.BlockBuddyRequest
  • {Boolean} isOnline()
    Indicates whether this buddy is online in the Buddy List system or not.
    Returns:
    {Boolean} true if the buddy is online.
    See also:
    SFS2X.Requests.BuddyList.GoOnlineRequest
  • {Boolean} isTemp()
    Indicates whether this buddy is temporary (non-persistent) in the current user's buddy list or not.
    Returns:
    {Boolean} true if the buddy is temporary.
  • {String} toString()
    Returns a string that contains the buddy id and name.
    Returns:
    {String} The string representation of the SFSBuddy object.