org.jivesoftware.smackx.chatstates.packet.ChatStateExtension Java Examples

The following examples show how to use org.jivesoftware.smackx.chatstates.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: RoomManager.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
public void updateTypingStatus(final ChatState chatState, final String jid, final int chatType) {
    if (!Preferences.isTesting()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Message message = new Message(JidCreate.from(jid));
                    message.addExtension(new ChatStateExtension(chatState));

                    if (chatType == Chat.TYPE_1_T0_1) {
                        message.setType(Message.Type.chat);
                    } else {
                        message.setType(Message.Type.groupchat);
                    }

                    sendMessageDependingOnType(message, jid, chatType);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
 
Example #2
Source File: AcknowledgedListener.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void processStanza(Stanza p) {
    // NOTE: the packet is not the acknowledgement itself but the packet
    // that is acknowledged
    if (!(p instanceof Message)) {
        // we are only interested in acks for messages
        return;
    }
    Message m = (Message) p;

    LOGGER.config("for message: "+m);

    if (DeliveryReceipt.from(m) != null) {
        // this is an ack for a 'received' message (XEP-0184) send by
        // KonMessageListener, ignore
        return;
    }

    if (m.getBody() == null && m.getExtensions().size() == 1 &&
            m.getExtension(ChatStateExtension.NAMESPACE) != null) {
        // this is an ack for a chat state notification (XEP-0085), ignore
        return;
    }

    mControl.onMessageSent(MessageIDs.to(m));
}
 
Example #3
Source File: OperationSetTypingNotificationsJabberImpl.java    From jitsi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and sends a packet for the new chat state.
 * @param chatState the new chat state.
 * @param jid the JID of the receiver.
 */
private void setCurrentState(ChatState chatState, Jid jid)
    throws NotConnectedException, InterruptedException
{
    String threadID = opSetBasicIM.getThreadIDForAddress(jid.asBareJid());
    if(threadID == null)
        return;

    Message message = new Message();
    ChatStateExtension extension = new ChatStateExtension(chatState);
    message.addExtension(extension);

    message.setTo(jid);
    message.setType(Message.Type.chat);
    message.setThread(threadID);
    message.setFrom(parentProvider.getConnection().getUser());
    parentProvider.getConnection().sendStanza(message);
}
 
Example #4
Source File: ChatRoomImpl.java    From Spark with Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example #5
Source File: Client.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
public void sendChatState(JID jid, String threadID, ChatState state) {
    Message message = new Message(jid.toBareSmack(), Message.Type.chat);
    if (!threadID.isEmpty())
        message.setThread(threadID);
    message.addExtension(new ChatStateExtension(state));

    this.sendPacket(message);
}
 
Example #6
Source File: ChatStateExtensionProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public ChatStateExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) {
    String chatStateString = parser.getName();
    ChatState state = ChatState.valueOf(chatStateString);

    return new ChatStateExtension(state);
}
 
Example #7
Source File: ChatStateManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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 if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
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 = StanzaBuilder.buildMessage().build();
    ChatStateExtension extension = new ChatStateExtension(newState);
    message.addExtension(extension);

    chat.send(message);
}
 
Example #8
Source File: OperationSetTypingNotificationsJabberImpl.java    From jitsi with Apache License 2.0 5 votes vote down vote up
@Override
public void processStanza(Stanza packet)
{
    Message msg = (Message) packet;
    ChatStateExtension ext = (ChatStateExtension) msg.getExtension(
        "http://jabber.org/protocol/chatstates");
    if(ext == null)
        return;
    stateChanged(ChatState.valueOf(ext.getElementName()), msg);
}
 
Example #9
Source File: ChatRoomImpl.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * Sends a message to the appropriate jid. The message is automatically added to the transcript.
    *
    * @param message the message to send.
    */
   @Override
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);
       }
   }
 
Example #10
Source File: KonMessageListener.java    From desktopclient-java with GNU General Public License v3.0 4 votes vote down vote up
private void processChatMessage(Message m) {
    LOGGER.config("message: "+m);
    // note: thread and subject are null if message comes from the Kontalk
    // Android client

    MessageIDs ids = MessageIDs.from(m);

    Date delayDate = getDelay(m);

    // process possible chat state notification (XEP-0085)
    ExtensionElement csExt = m.getExtension(ChatStateExtension.NAMESPACE);
    ChatState chatState = null;
    if (csExt != null) {
        chatState = ((ChatStateExtension) csExt).getChatState();
        mControl.onChatStateNotification(ids,
                Optional.ofNullable(delayDate),
                chatState);
    }

    // must be an incoming message
    // get content/text from body and/or encryption/url extension
    MessageContent content = ClientUtils.parseMessageContent(m, false);

    // make sure not to save a message without content
    if (content.isEmpty()) {
        if (chatState == null) {
            LOGGER.warning("can't find any content in message");
        } else if (chatState == ChatState.active) {
            LOGGER.info("only active chat state");
        }
        return;
    }

    // add message
    mControl.onNewInMessage(ids, Optional.ofNullable(delayDate), content);

    // send a 'received' for a receipt request (XEP-0184)
    DeliveryReceiptRequest request = DeliveryReceiptRequest.from(m);
    if (request != null && !ids.xmppID.isEmpty()) {
        Message received = new Message(m.getFrom(), Message.Type.chat);
        received.addExtension(new DeliveryReceipt(ids.xmppID));
        mClient.sendPacket(received);
    }
}