Package sfs2x.client.entities
Class SFSBuddy
- java.lang.Object
-
- sfs2x.client.entities.SFSBuddy
-
- All Implemented Interfaces:
Buddy
public class SFSBuddy extends java.lang.Object implements Buddy
The SFSBuddy object represents a buddy in the current user's buddies list.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 buddies list. 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. 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 buddies 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 buddies list whenever another user adds him to his own buddies list. In this way users can "see" each other and exchange messages. If the current user doesn't add that temporary buddy to his buddies 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 information 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.
- See Also:
SmartFox.buddyManager
,BuddyVariable
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearVolatileVariables()
* API internal usage only *boolean
containsVariable(java.lang.String varName)
Indicates whether this buddy has the specified Buddy Variable set or not.static Buddy
fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray arr)
* API internal usage only *int
getId()
Indicates the id of this buddy.java.lang.String
getName()
Indicates the name of this buddy.java.lang.String
getNickName()
Returns the nickname of this buddy.java.util.List<BuddyVariable>
getOfflineVariables()
Retrieves the list of persistent Buddy Variables of this buddy.java.util.List<BuddyVariable>
getOnlineVariables()
Retrieves the list of non-persistent Buddy Variables of this buddy.java.lang.String
getState()
Returns the custom state of this buddy.BuddyVariable
getVariable(java.lang.String varName)
Retrieves a Buddy Variable from its name.java.util.List<BuddyVariable>
getVariables()
Returns a list of BuddyVariable objects associated with the buddy.boolean
isBlocked()
Indicates whether this buddy is blocked in the current user's buddies list or not.boolean
isOnline()
Indicates whether this buddy is online in the Buddy List system or not.boolean
isTemp()
Indicates whether this buddy is temporary (non-persistent) in the current user's buddies list or not.void
removeVariable(java.lang.String varName)
* API internal usage only *void
setBlocked(boolean blocked)
* API internal usage only *void
setId(int id)
* API internal usage only *void
setVariable(BuddyVariable bVar)
* API internal usage only *void
setVariables(java.util.List<BuddyVariable> variables)
* API internal usage only *java.lang.String
toString()
Returns a string that contains the buddy name and id.
-
-
-
Constructor Detail
-
SFSBuddy
public SFSBuddy(int id, java.lang.String name, boolean isBlocked, boolean isTemp)
Creates a new SFSBuddy instance.NOTE: developers never instantiate a SFSBuddy manually: this is done by the SmartFoxServer 2X API internally.
- Parameters:
id
- The buddy id.name
- The buddy name.isBlocked
- Iftrue
, the buddy being created is blocked by the current user.isTemp
- Iftrue
, the buddy being created is temporary in the current client.
-
SFSBuddy
public SFSBuddy(int id, java.lang.String name, boolean isBlocked)
-
SFSBuddy
public SFSBuddy(int id, java.lang.String name)
-
-
Method Detail
-
fromSFSArray
public static Buddy fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray arr)
* API internal usage only *
-
getId
public int getId()
Description copied from interface:Buddy
Indicates the id of this buddy. This is equal to the id assigned by SmartFoxServer to the corresponding user.- Specified by:
getId
in interfaceBuddy
- See Also:
User.getId()
-
getName
public java.lang.String getName()
Description copied from interface:Buddy
Indicates the name of this buddy. This is equal to the name of the corresponding user.- Specified by:
getName
in interfaceBuddy
- See Also:
User.getName()
-
isBlocked
public boolean isBlocked()
Description copied from interface:Buddy
Indicates whether this buddy is blocked in the current user's buddies list or not. A buddy can be blocked by means of a BlockBuddyRequest request.- Specified by:
isBlocked
in interfaceBuddy
- See Also:
BlockBuddyRequest
-
isOnline
public boolean isOnline()
Description copied from interface:Buddy
Indicates whether this buddy is online in the Buddy List system or not.
-
isTemp
public boolean isTemp()
Description copied from interface:Buddy
Indicates whether this buddy is temporary (non-persistent) in the current user's buddies list or not.
-
getState
public java.lang.String getState()
Description copied from interface:Buddy
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 IBuddyManager.buddyStates property.
- Specified by:
getState
in interfaceBuddy
- See Also:
IBuddyManager.getBuddyStates()
-
getNickName
public java.lang.String getNickName()
Description copied from interface:Buddy
Returns the nickname of this buddy. If the nickname is not set,null
is returned.- Specified by:
getNickName
in interfaceBuddy
-
getVariables
public java.util.List<BuddyVariable> getVariables()
Description copied from interface:Buddy
Returns a list of BuddyVariable objects associated with the buddy.- Specified by:
getVariables
in interfaceBuddy
- See Also:
BuddyVariable
,Buddy.getVariable(String)
-
getVariable
public BuddyVariable getVariable(java.lang.String varName)
Description copied from interface:Buddy
Retrieves a Buddy Variable from its name.- Specified by:
getVariable
in interfaceBuddy
- Parameters:
varName
- The name of the Buddy Variable to be retrieved.- Returns:
- The BuddyVariable object representing the Buddy Variable, or
null
if no Buddy Variable with the passed name is associated with this buddy. - See Also:
Buddy.getVariables()
,SetBuddyVariablesRequest
-
containsVariable
public boolean containsVariable(java.lang.String varName)
Description copied from interface:Buddy
Indicates whether this buddy has the specified Buddy Variable set or not.- Specified by:
containsVariable
in interfaceBuddy
- Parameters:
varName
- The name of the Buddy Variable whose existence must be checked.- Returns:
true
if a Buddy Variable with the passed name is set for this buddy.
-
getOfflineVariables
public java.util.List<BuddyVariable> getOfflineVariables()
Description copied from interface:Buddy
Retrieves the list of persistent Buddy Variables of this buddy.- Specified by:
getOfflineVariables
in interfaceBuddy
- Returns:
- A List of BuddyVariable objects.
- See Also:
BuddyVariable.isOffline()
-
getOnlineVariables
public java.util.List<BuddyVariable> getOnlineVariables()
Description copied from interface:Buddy
Retrieves the list of non-persistent Buddy Variables of this buddy.- Specified by:
getOnlineVariables
in interfaceBuddy
- Returns:
- A List of BuddyVariable objects.
- See Also:
BuddyVariable.isOffline()
-
setVariable
public void setVariable(BuddyVariable bVar)
Description copied from interface:Buddy
* API internal usage only *- Specified by:
setVariable
in interfaceBuddy
-
setVariables
public void setVariables(java.util.List<BuddyVariable> variables)
* API internal usage only *- Specified by:
setVariables
in interfaceBuddy
-
setBlocked
public void setBlocked(boolean blocked)
* API internal usage only *- Specified by:
setBlocked
in interfaceBuddy
-
removeVariable
public void removeVariable(java.lang.String varName)
* API internal usage only *- Specified by:
removeVariable
in interfaceBuddy
-
clearVolatileVariables
public void clearVolatileVariables()
* API internal usage only *- Specified by:
clearVolatileVariables
in interfaceBuddy
-
toString
public java.lang.String toString()
Returns a string that contains the buddy name and id.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation of the SFSBuddy object.
-
-