Search in sources :

Example 1 with ChatStateType

use of net.sf.kraken.type.ChatStateType in project Openfire by igniterealtime.

the class AbstractChatStateUtil method isPaused.

/**
     * Changes the chat state of the sender to 'paused' in the context of a
     * conversation with the receiver. Additionally, a future chat state change
     * to 'inactive' is scheduled, replacing any existing scheduled chat state
     * changes.
     * 
     * If execution of this method changes the current chat state,
     * {@link #sendIsPaused(JID, JID)} will be triggered exactly once.
     * 
     * The delay after which the change to the future chat state will be reset
     * no matter what the current chat state is.
     * 
     * @param sender
     *            The entity of which the chat state is changing.
     * @param receiver
     *            The entity that is to receive a chat state change
     *            notification.
     */
public void isPaused(JID sender, JID receiver) {
    final ChatStateSession session = new ChatStateSession(sender, receiver);
    final ChatStateType newState = ChatStateType.paused;
    synchronized (mutex) {
        final ChatStateType previousState = currentStates.put(session, newState);
        if (previousState != newState) {
            sendIsPaused(sender, receiver);
        }
        // Replace any existing timeout with a new timeout: should go to
        // 'inactive' in 90 seconds (2 minutes - 30 seconds!)
        scheduleStateChange(90, TimeUnit.SECONDS, ChatStateType.inactive, session);
    }
}
Also used : ChatStateType(net.sf.kraken.type.ChatStateType)

Example 2 with ChatStateType

use of net.sf.kraken.type.ChatStateType 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)

Example 3 with ChatStateType

use of net.sf.kraken.type.ChatStateType in project Openfire by igniterealtime.

the class AbstractChatStateUtil method isGone.

/**
     * Changes the chat state of the sender to 'gone' in the context of a
     * conversation with the receiver.
     * 
     * If execution of this method changes the current chat state,
     * {@link #sendIsGone(JID, JID)} will be triggered exactly once.
     * 
     * Any scheduled future chat state will be canceled no matter what the
     * current chat state is.
     * 
     * @param sender
     *            The entity of which the chat state is changing.
     * @param receiver
     *            The entity that is to receive a chat state change
     *            notification.
     */
public void isGone(JID sender, JID receiver) {
    // a somewhat special case. Chat state 'gone' is represented by having
    // no chat state in the map.
    final ChatStateSession session = new ChatStateSession(sender, receiver);
    synchronized (mutex) {
        // Remove this conversation from the HashMap (this prevents memory
        // leaks).
        final ChatStateType previousState = currentStates.remove(session);
        if (previousState != null) {
            sendIsGone(sender, receiver);
        }
        // remove any existing timeouts
        final ScheduledFuture<?> oldFuture = pendingStateChanges.remove(session);
        if (oldFuture != null) {
            oldFuture.cancel(false);
        }
    }
}
Also used : ChatStateType(net.sf.kraken.type.ChatStateType)

Example 4 with ChatStateType

use of net.sf.kraken.type.ChatStateType in project Openfire by igniterealtime.

the class AbstractChatStateUtil method isInactive.

/**
     * Changes the chat state of the sender to 'inactive' in the context of a
     * conversation with the receiver. Additionally, a future chat state change
     * to 'gone' is scheduled, replacing any existing scheduled chat state
     * changes.
     * 
     * If execution of this method changes the current chat state,
     * {@link #sendIsInactive(JID, JID)} will be triggered exactly once.
     * 
     * The delay after which the change to the future chat state will be reset
     * no matter what the current chat state is.
     * 
     * @param sender
     *            The entity of which the chat state is changing.
     * @param receiver
     *            The entity that is to receive a chat state change
     *            notification.
     */
public void isInactive(JID sender, JID receiver) {
    final ChatStateSession session = new ChatStateSession(sender, receiver);
    final ChatStateType newState = ChatStateType.inactive;
    synchronized (mutex) {
        final ChatStateType previousState = currentStates.put(session, newState);
        if (previousState != newState) {
            sendIsInactive(sender, receiver);
        }
        // Replace any existing timeout with a new timeout: should go to
        // 'gone'
        // in 8 minutes (10 minutes - 2 minutes!)
        scheduleStateChange(480, TimeUnit.SECONDS, ChatStateType.gone, session);
    }
}
Also used : ChatStateType(net.sf.kraken.type.ChatStateType)

Example 5 with ChatStateType

use of net.sf.kraken.type.ChatStateType in project Openfire by igniterealtime.

the class AbstractChatStateUtil method isComposing.

/**
     * Changes the chat state of the sender to 'composing' in the context of a
     * conversation with the receiver. Additionally, a future chat state change
     * to 'paused' is scheduled, replacing any existing scheduled chat state
     * changes.
     * 
     * If execution of this method changes the current chat state,
     * {@link #sendIsComposing(JID, JID)} will be triggered exactly once.
     * 
     * The delay after which the change to the future chat state will be reset
     * no matter what the current chat state is.
     * 
     * @param sender
     *            The entity of which the chat state is changing.
     * @param receiver
     *            The entity that is to receive a chat state change
     *            notification.
     */
public void isComposing(JID sender, JID receiver) {
    final ChatStateSession session = new ChatStateSession(sender, receiver);
    final ChatStateType newState = ChatStateType.composing;
    synchronized (mutex) {
        final ChatStateType previousState = currentStates.put(session, newState);
        if (previousState != newState) {
            sendIsComposing(sender, receiver);
        }
        // Replace any existing timeout with a new timeout: should go to
        // 'paused' in 30 seconds
        scheduleStateChange(30, TimeUnit.SECONDS, ChatStateType.paused, session);
    }
}
Also used : ChatStateType(net.sf.kraken.type.ChatStateType)

Aggregations

ChatStateType (net.sf.kraken.type.ChatStateType)6 AttentionExtension (net.sf.kraken.protocols.xmpp.packet.AttentionExtension)1 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)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