Class SFSBuddyApi

java.lang.Object
com.smartfoxserver.api.SFSBuddyApi
All Implemented Interfaces:
ISFSBuddyApi

public class SFSBuddyApi extends Object implements ISFSBuddyApi
Provides access to the API for managing Buddies and Buddy lists.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.slf4j.Logger
     
    protected final com.smartfoxserver.api.ISFSBuddyResponseApi
     
    protected final SmartFoxServer
     
    protected final ISFSApi
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addBuddy(User owner, String buddyName, boolean isTemp, boolean fireClientEvent, boolean fireServerEvent)
    Adds a new buddy to the BuddyList of the specified User.
    void
    blockBuddy(User owner, String buddyName, boolean isBlocked, boolean fireClientEvent, boolean fireServerEvent)
    Block/Unblock a Buddy in the owner's BuddyList Blocked buddies won't be able to see the owner online status or send messages to that User
    com.smartfoxserver.api.ISFSBuddyResponseApi
    void
    goOnline(User user, boolean online, boolean fireServerEvent)
    Toggles the Buddy ONLINE state of the User.
    initBuddyList(User user, boolean fireServerEvent)
    Initializes the buddy list for the requested User.
    protected void
     
    void
    removeBuddy(User owner, String buddyName, boolean fireClientEvent, boolean fireServerEvent)
    Remove a Buddy from the owner's BuddyList
    void
    sendBuddyMessage(User sender, User recipient, String message, ISFSObject params)
    Send a Buddy Message to any Buddy in your list.
    void
    setBuddyVariables(User owner, List<BuddyVariable> buddyVariables, boolean fireClientEvent, boolean fireServerEvent)
    Set any number of BuddyVariables for the specified owner

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sfs

      protected final SmartFoxServer sfs
    • log

      protected final org.slf4j.Logger log
    • responseAPI

      protected final com.smartfoxserver.api.ISFSBuddyResponseApi responseAPI
    • sfsApi

      protected final ISFSApi sfsApi
  • Constructor Details

  • Method Details

    • getResponseAPI

      public com.smartfoxserver.api.ISFSBuddyResponseApi getResponseAPI()
      Specified by:
      getResponseAPI in interface ISFSBuddyApi
    • initBuddyList

      public BuddyList initBuddyList(User user, boolean fireServerEvent) throws IOException
      Initializes the buddy list for the requested User. This involves loading previous data from the BuddyList storage.
      Specified by:
      initBuddyList in interface ISFSBuddyApi
      Parameters:
      user - the User
      fireServerEvent - if true fires a server side event (BUDDY_LIST_INIT)
      Returns:
      the loaded BuddyList
      Throws:
      IOException
    • goOnline

      public void goOnline(User user, boolean online, boolean fireServerEvent)
      Toggles the Buddy ONLINE state of the User. All clients who have this User as their Buddy will be notified about the change.
      Specified by:
      goOnline in interface ISFSBuddyApi
      Parameters:
      user - the User
      online - the online status
      fireServerEvent - if true fires a server side event (BUDDY_ONLINE)
    • addBuddy

      public void addBuddy(User owner, String buddyName, boolean isTemp, boolean fireClientEvent, boolean fireServerEvent) throws SFSBuddyListException
      Adds a new buddy to the BuddyList of the specified User.
      Specified by:
      addBuddy in interface ISFSBuddyApi
      Parameters:
      owner - the owner User
      buddyName - the name of the buddy to add
      isTemp - if true, the Buddy is only temporary and will be lost when the user logs out
      fireClientEvent - if true, send a client update
      fireServerEvent - if true, fire a server event (BUDDY_ADDED)
      Throws:
      SFSBuddyListException - an error might occur if the BuddyList is full or the buddy was already added
    • removeBuddy

      public void removeBuddy(User owner, String buddyName, boolean fireClientEvent, boolean fireServerEvent)
      Remove a Buddy from the owner's BuddyList
      Specified by:
      removeBuddy in interface ISFSBuddyApi
      Parameters:
      owner - the owner
      buddyName - the Buddy name
      fireClientEvent - if true send a client update
      fireServerEvent - if true fire a server side event (BUDDY_REMOVED)
    • blockBuddy

      public void blockBuddy(User owner, String buddyName, boolean isBlocked, boolean fireClientEvent, boolean fireServerEvent)
      Block/Unblock a Buddy in the owner's BuddyList Blocked buddies won't be able to see the owner online status or send messages to that User
      Specified by:
      blockBuddy in interface ISFSBuddyApi
      Parameters:
      owner - the BuddyList owner
      buddyName - the name of the Buddy to block/unblock
      isBlocked - the 'blocked' flag
      fireClientEvent - if true send a client update
      fireServerEvent - if true fire a server side event (BUDDY_BLOCK_UPDATE)
    • setBuddyVariables

      public void setBuddyVariables(User owner, List<BuddyVariable> buddyVariables, boolean fireClientEvent, boolean fireServerEvent) throws SFSBuddyListException
      Set any number of BuddyVariables for the specified owner
      Specified by:
      setBuddyVariables in interface ISFSBuddyApi
      Parameters:
      owner - the owner User
      buddyVariables - a list of variables
      fireClientEvent - if true, send a client update
      fireServerEvent - if true, fire a server event (BUDDY_VARIABLES_UPDATE)
      Throws:
      SFSBuddyListException - an error might occur if the limit of variables allowed is exceeded
    • sendBuddyMessage

      public void sendBuddyMessage(User sender, User recipient, String message, ISFSObject params) throws SFSBuddyListException
      Send a Buddy Message to any Buddy in your list. A Buddy message is similar to a Private Message but it is meant to work with the BuddyList taking into account the Buddy states (online/offline/blocked etc.)
      Specified by:
      sendBuddyMessage in interface ISFSBuddyApi
      Parameters:
      sender - the sender of the message
      recipient - the recipient of the message (must be a Buddy in the sender's BuddyList)
      message - the message
      params - custom parameters
      Throws:
      SFSBuddyListException - thrown if the Buddy is not in the sender's Buddy List or if the recipient has blocked the sender
    • initializeBuddyState

      protected void initializeBuddyState(User user) throws SFSBuddyListException
      Throws:
      SFSBuddyListException