Search in sources :

Example 1 with AttentionExtension

use of net.sf.kraken.protocols.xmpp.packet.AttentionExtension in project Openfire by igniterealtime.

the class XMPPListener method processMessage.

/**
     * Handles incoming messages.
     *
     * @param chat Chat instance this message is associated with.
     * @param message Message received.
     */
public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {
    Log.debug("Received " + getSession().getTransport().getType().name() + " message: " + message.toXML());
    try {
        final BaseTransport<XMPPBuddy> transport = getSession().getTransport();
        final JID legacyJID = transport.convertIDToJID(message.getFrom());
        final JID localJID = getSession().getJID();
        final PacketExtension pe = message.getExtension("x", NameSpace.X_DELAY);
        final PacketExtension attExt = message.getExtension(AttentionExtension.ELEMENT_NAME, AttentionExtension.NAMESPACE);
        if (pe != null && pe instanceof DelayInformation) {
            DelayInformation di = (DelayInformation) pe;
            transport.sendOfflineMessage(localJID, legacyJID, message.getBody(), di.getStamp(), di.getReason());
        } else if (attExt != null && (attExt instanceof AttentionExtension)) {
            transport.sendAttentionNotification(localJID, legacyJID, message.getBody());
        } else {
            // see if we got sent chat state notifications
            final PacketExtension cse = message.getExtension("http://jabber.org/protocol/chatstates");
            if (cse != null && cse instanceof ChatStateExtension) {
                final String chatState = cse.getElementName();
                try {
                    final ChatStateType cst = ChatStateType.valueOf(ChatStateType.class, chatState);
                    switch(cst) {
                        case active:
                            // included with that chat message below.
                            if (message.getBody() == null || message.getBody().trim().length() == 0) {
                                transport.sendChatActiveNotification(localJID, legacyJID);
                            }
                            break;
                        case composing:
                            transport.sendComposingNotification(localJID, legacyJID);
                            break;
                        case gone:
                            transport.sendChatGoneNotification(localJID, legacyJID);
                            break;
                        case inactive:
                            transport.sendChatInactiveNotification(localJID, legacyJID);
                            break;
                        case paused:
                            transport.sendComposingPausedNotification(localJID, legacyJID);
                            break;
                        default:
                            Log.debug("Unexpected chat state recieved: " + cst);
                            break;
                    }
                } catch (IllegalArgumentException ex) {
                    Log.warn("Illegal chat state notification " + "received from legacy domain: " + chatState);
                }
            }
            if (message.getType() == Type.error) {
                Log.debug("Received an error message! Message: " + message.toXML());
                transport.sendMessage(localJID, legacyJID, message.getBody(), Message.Type.error);
            } else {
                transport.sendMessage(localJID, legacyJID, message.getBody());
            }
        }
    //            if (message.getProperty("time") == null || message.getProperty("time").equals("")) {
    //            }
    //            else {
    //                getSession().getTransport().sendOfflineMessage(
    //                        getSession().getJID(),
    //                        getSession().getTransport().convertIDToJID(message.getFrom()),
    //                        message.getBody(),
    //                        Message.Type.chat,
    //                        message.getProperty("time").toString()
    //                );
    //            }
    } catch (Exception ex) {
        Log.debug("E001:" + ex.getMessage(), ex);
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) ChatStateType(net.sf.kraken.type.ChatStateType) JID(org.xmpp.packet.JID) DelayInformation(org.jivesoftware.smackx.packet.DelayInformation) ChatStateExtension(org.jivesoftware.smackx.packet.ChatStateExtension) AttentionExtension(net.sf.kraken.protocols.xmpp.packet.AttentionExtension)

Aggregations

AttentionExtension (net.sf.kraken.protocols.xmpp.packet.AttentionExtension)1 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)1 ChatStateType (net.sf.kraken.type.ChatStateType)1 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)1 ChatStateExtension (org.jivesoftware.smackx.packet.ChatStateExtension)1 DelayInformation (org.jivesoftware.smackx.packet.DelayInformation)1 JID (org.xmpp.packet.JID)1