Class 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
    • Constructor Summary

      Constructors 
      Constructor Description
      SFSBuddy​(int id, java.lang.String name)  
      SFSBuddy​(int id, java.lang.String name, boolean isBlocked)  
      SFSBuddy​(int id, java.lang.String name, boolean isBlocked, boolean isTemp)
      Creates a new SFSBuddy instance.
    • 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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 - If true, the buddy being created is blocked by the current user.
        isTemp - If true, 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 interface Buddy
        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 interface Buddy
        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 interface Buddy
        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.
        Specified by:
        isOnline in interface Buddy
      • 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.
        Specified by:
        isTemp in interface Buddy
      • 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 interface Buddy
        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 interface Buddy
      • getVariable

        public BuddyVariable getVariable​(java.lang.String varName)
        Description copied from interface: Buddy
        Retrieves a Buddy Variable from its name.
        Specified by:
        getVariable in interface Buddy
        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 interface Buddy
        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.
      • setVariable

        public void setVariable​(BuddyVariable bVar)
        Description copied from interface: Buddy
        * API internal usage only *
        Specified by:
        setVariable in interface Buddy
      • setVariables

        public void setVariables​(java.util.List<BuddyVariable> variables)
        * API internal usage only *
        Specified by:
        setVariables in interface Buddy
      • setId

        public void setId​(int id)
        * API internal usage only *
        Specified by:
        setId in interface Buddy
      • setBlocked

        public void setBlocked​(boolean blocked)
        * API internal usage only *
        Specified by:
        setBlocked in interface Buddy
      • removeVariable

        public void removeVariable​(java.lang.String varName)
        * API internal usage only *
        Specified by:
        removeVariable in interface Buddy
      • clearVolatileVariables

        public void clearVolatileVariables()
        * API internal usage only *
        Specified by:
        clearVolatileVariables in interface Buddy
      • toString

        public java.lang.String toString()
        Returns a string that contains the buddy name and id.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation of the SFSBuddy object.