Class PrivateMessageRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class PrivateMessageRequest
    extends sfs2x.client.requests.GenericMessageRequest
    Sends a private chat message.

    The private message is dispatched to a specific user, who can be in any server Room, or even in no Room at all. The message is delivered by means of the privateMessage event. It is also returned to the sender: this allows showing the messages in the correct order in the application interface. It is also possible to send an optional object together with the message: it can contain custom parameters useful to transmit, for example, additional informations related to the message, like the text font or color, or other formatting details.

    Example
    The following example sends a private message and handles the respective event:

     private void someMethod() {
         sfs.addEventListener(SFSEvent.PRIVATE_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
                 User sender = (User)evt.getArguments().get("sender");
                 
                 if (sender != sfs.getMySelf())
                     System.out.println("User " + sender.getName() + " sent me this PM:" + evt.getArguments().get("message"));
             }
         });
         
         // Send a private message to Jack
         User user = sfs.getUserManager().getUserByName("Jack");
         sfs.send(new PrivateMessageRequest("Hello everyone!", user.getId()));
     }
     
    See Also:
    SFSEvent.PRIVATE_MESSAGE
    • Constructor Detail

      • PrivateMessageRequest

        public PrivateMessageRequest​(java.lang.String message,
                                     int recipientId,
                                     com.smartfoxserver.v2.entities.data.ISFSObject params)
        Creates a new PrivateMessageRequest 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 to the recipient user.
        recipientId - The id of the user to which the message is to be sent.
        params - An instance of SFSObject containing additional custom parameters to be sent to the message recipient (for example the color of the text, etc).
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), SFSObject