org.jivesoftware.smackx.receipts.DeliveryReceiptRequest Java Examples

The following examples show how to use org.jivesoftware.smackx.receipts.DeliveryReceiptRequest. 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: 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);
    }
}