sfs2x.client.requests.buddylist
Class BuddyMessageRequest

java.lang.Object
  extended by sfs2x.client.requests.BaseRequest
      extended by sfs2x.client.requests.GenericMessageRequest
          extended by sfs2x.client.requests.buddylist.BuddyMessageRequest
All Implemented Interfaces:
sfs2x.client.requests.IRequest

public class BuddyMessageRequest
extends sfs2x.client.requests.GenericMessageRequest

Sends a message to a buddy in the current user's buddies list.

Messages sent to buddies using the BuddyMessageRequest request are similar to the standard private messages (see the PrivateMessageRequest request) but are specifically designed for the Buddy List system: they don't require any Room parameter, nor they require that users joined a Room. Additionally, buddy messages are subject to specific validation, such as making sure that the recipient is in the sender's buddies list and the sender is not blocked by the recipient.

If the operation is successful, a buddyMessage event is dispatched in both the sender and recipient clients.

NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description).

Example
The following example sends a message to a buddy and handles the related event:

 private void someMethod() {
     sfs.addEventListener(SFSBuddyEvent.BUDDY_MESSAGE, new IEventListener() {
         public void dispatch(BaseEvent evt) throws SFSException {
             // As messages are forwarded to the sender too,
             // I have to check if I am the sender
             boolean isItMe = (Boolean)evt.getArguments().get("isItMe");
             Buddy sender = (Buddy)evt.getArguments().get("buddy");
             
             if (isItMe)
                 System.out.println("I said:" + evt.getArguments().get("message"));
             else
                 System.out.println("My buddy " + sender.getName() + " said:" + evt.getArguments().get("message"));
         }
     });
     
     // Get the recipient of the message, in this case my buddy Jack
     Buddy buddy = sfs.getBuddyManager().getBuddyByName("Jack");
     
     // Send a message to Jack
     sfs.send(new BuddyMessageRequest("Hello Jack!", buddy));
 }
 

See Also:
SFSBuddyEvent.BUDDY_MESSAGE, InitBuddyListRequest

Field Summary
 
Fields inherited from class sfs2x.client.requests.GenericMessageRequest
KEY_MESSAGE, KEY_MESSAGE_TYPE, KEY_RECIPIENT, KEY_RECIPIENT_MODE, KEY_ROOM_ID, KEY_SENDER_DATA, KEY_USER_ID, KEY_XTRA_PARAMS
 
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
 
Constructor Summary
BuddyMessageRequest(java.lang.String message, Buddy targetBuddy)
           
BuddyMessageRequest(java.lang.String message, Buddy targetBuddy, com.smartfoxserver.v2.entities.data.ISFSObject params)
          Creates a new BuddyMessageRequest instance.
 
Method Summary
 
Methods inherited from class sfs2x.client.requests.GenericMessageRequest
execute, validate
 
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuddyMessageRequest

public BuddyMessageRequest(java.lang.String message,
                           Buddy targetBuddy)
See Also:
BuddyMessageRequest(String, Buddy, ISFSObject)

BuddyMessageRequest

public BuddyMessageRequest(java.lang.String message,
                           Buddy targetBuddy,
                           com.smartfoxserver.v2.entities.data.ISFSObject params)
Creates a new BuddyMessageRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters:
message - The message to be sent to a buddy.
targetBuddy - The Buddy object corresponding to the message recipient.
params - An instance of SFSObject containing additional custom parameters (e.g. the message color, an emoticon id, etc).
See Also:
SmartFox.send(sfs2x.client.requests.IRequest), SFSObject