org.jivesoftware.smackx.packet.ChatStateExtension Java Examples

The following examples show how to use org.jivesoftware.smackx.packet.ChatStateExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiUserChatStateManager.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the current state of the provided chat. This method will send an empty bodied Message
 * packet with the state attached as a {@link org.jivesoftware.smack.packet.PacketExtension}, iff
 * the new chat state is different than the last state.
 *
 * @param newState the new state of the chat
 * @throws org.jivesoftware.smack.XMPPException when there is an error sending the message packet.
 */
public void setState(ChatState newState) throws XMPPException {
  if (muc == null || newState == null) {
    throw new IllegalArgumentException("Arguments cannot be null.");
  }

  // last and new ChatState are the same
  if (this.lastState == newState) {
    return;
  }

  /*
   * Creates a Message with an empty body. A body is needed because the
   * Message.Type.groupchat requires one.
   */
  try {
    Message message = muc.createMessage();
    message.setBody("");
    ChatStateExtension extension = new ChatStateExtension(newState);
    message.addExtension(extension);
    muc.sendMessage(message);
  } catch (Exception e1) {
    log.debug("Couldn't send state (" + e1.getMessage() + ")");
  }

  this.lastState = newState;
}