@Override public ChatStateExtension parse(XmlPullParser parser, int initialDepth) throws Exception { String chatStateString = parser.getName(); ChatState state = ChatState.valueOf(chatStateString); return new ChatStateExtension(state); }
@Override public void newOutgoingMessage(EntityBareJid to, Message message, Chat chat) { if (chat == null) { return; } // if message already has a chatStateExtension, then do nothing, if (!filter.accept(message)) { return; } // otherwise add a chatState extension if necessary. if (updateChatState(chat, ChatState.active)) { message.addExtension(new ChatStateExtension(ChatState.active)); } } });
/** * Sets the current state of the provided chat. This method will send an empty bodied Message * stanza with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if * and only if the new chat state is different than the last state. * * @param newState the new state of the chat * @param chat the chat. * @throws NotConnectedException * @throws InterruptedException */ public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException, InterruptedException { if (chat == null || newState == null) { throw new IllegalArgumentException("Arguments cannot be null."); } if (!updateChatState(chat, newState)) { return; } Message message = new Message(); ChatStateExtension extension = new ChatStateExtension(newState); message.addExtension(extension); chat.send(message); }
message.addExtension(new ChatStateExtension(ChatState.active));
@Override protected void sendChatState(ChatState state) throws SmackException.NotConnectedException, InterruptedException { if ( !active ) { return; } final Message message = new Message(); message.setType( Message.Type.chat ); message.setTo( participantJID ); message.setFrom( SparkManager.getSessionManager().getJID()); if (threadID == null) { threadID = StringUtils.randomString(6); } message.setThread(threadID); message.addExtension( new ChatStateExtension( state ) ); SparkManager.getConnection().sendStanza( message ); } }
/** * Sends a message to the appropriate jid. The message is automatically added to the transcript. * * @param message the message to send. */ public void sendMessage(Message message) { //Before sending message, let's add our full jid for full verification //Set message attributes before insertMessage is called - this is useful when transcript window is extended //more information will be available to be displayed for the chat area Document message.setType(Message.Type.chat); message.setTo(participantJID); message.setFrom(SparkManager.getSessionManager().getJID()); displaySendMessage( message ); // No need to request displayed or delivered as we aren't doing anything with this // information. MessageEventManager.addNotificationsRequests(message, true, false, false, true); // Set chat state to 'active' message.addExtension( new ChatStateExtension( ChatState.active ) ); // Send the message that contains the notifications request try { fireOutgoingMessageSending(message); SparkManager.getConnection().sendStanza(message); } catch (Exception ex) { Log.error("Error sending message", ex); } }