Class InviteUsersRequest

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

    public class InviteUsersRequest
    extends BaseRequest
    Sends a generic invitation to a list of users.

    Invitations can be used for different purposes, such as requesting users to join a game or visit a specific Room, asking the permission to add them as buddies, etc. Invited users receive the invitation as an invitation event dispatched to their clients: they can accept or refuse it by means of the InvitationReplyRequest request, which must be sent within the specified amount of time.

    Example
    The following example sends an invitation to join the current user in his private Room; the invitation contains a custom message and the Room name and password, so that the recipient clients can join the Room if the users accept the invitation:

     private void someMethod() {
         // Add a listener to the invitation reply
         sfs.addEventListener(SFSEvent.INVITATION_REPLY, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 // If at least one recipient accepted the invitation, make me join my private Room to meet him there
                 if ((Integer) evt.getArguments().get("reply") == InvitationReply.ACCEPT) {
                     Room currentRoom = sfs.getLastJoinedRoom();
                     if (!currentRoom.getName().equals("Kermit's room")) {
                         sfs.send(new JoinRoomRequest("Kermit's room"));
                     }
                 }
                 else
                 {
                     System.out.println((User) evt.getArguments().get("invitee") + " refused the invitation");
                 }
             }
         });
         
         // Choose the invitation recipients
         User friend1 = sfs.getUserManager().getUserByName("Piggy");
         User friend2 = sfs.getUserManager().getUserByName("Gonzo");
         List<Object> friendList = new ArrayList<Object>();
         friendList.add(friend1);
         friendList.add(friend2);
         
         // Set the custom invitation details
         ISFSObject params = new SFSObject();
         params.putUtfString("msg", "Would you like to join me in my private room?");
         params.putUtfString("roomName", "Kermit's room");
         params.putUtfString("roomPwd", "drowssap");
         
         // Send the invitation; recipients have 20 seconds to reply before the invitation expires
         sfs.send(new InviteUsersRequest(friendList, 20, params));
     }
     
    See Also:
    SFSEvent.INVITATION, InvitationReplyRequest
    • Field Detail

      • KEY_USER

        public static final java.lang.String KEY_USER
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_USER_ID

        public static final java.lang.String KEY_USER_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_INVITATION_ID

        public static final java.lang.String KEY_INVITATION_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_TIME

        public static final java.lang.String KEY_TIME
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PARAMS

        public static final java.lang.String KEY_PARAMS
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_INVITEE_ID

        public static final java.lang.String KEY_INVITEE_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_INVITED_USERS

        public static final java.lang.String KEY_INVITED_USERS
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_REPLY_ID

        public static final java.lang.String KEY_REPLY_ID
        * API internal usage only *
        See Also:
        Constant Field Values
      • MAX_INVITATIONS_FROM_CLIENT_SIDE

        public static final int MAX_INVITATIONS_FROM_CLIENT_SIDE
        * API internal usage only *
        See Also:
        Constant Field Values
      • MIN_EXPIRY_TIME

        public static final int MIN_EXPIRY_TIME
        * API internal usage only *
        See Also:
        Constant Field Values
      • MAX_EXPIRY_TIME

        public static final int MAX_EXPIRY_TIME
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • InviteUsersRequest

        public InviteUsersRequest​(java.util.List<java.lang.Object> invitedUsers,
                                  int secondsForAnswer,
                                  com.smartfoxserver.v2.entities.data.ISFSObject params)
        Creates a new InviteUsersRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        invitedUsers - A list of User objects representing user to send the invitation to.
        secondsForAnswer - The number of seconds available to each invited user to reply to the invitation (recommended range: 15 to 40 seconds).
        params - An instance of SFSObject containing custom parameters which specify the invitation details.
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), User, SFSObject
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *