Search in sources :

Example 6 with Presence

use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.

the class XMPPSession method sendChatState.

/**
     * @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID, net.sf.kraken.type.ChatStateType)
     */
@Override
public void sendChatState(JID jid, ChatStateType chatState) {
    final Presence presence = conn.getRoster().getPresence(jid.toString());
    if (presence == null || presence.getType().equals(Presence.Type.unavailable)) {
        // don't send chat state to contacts that are offline.
        return;
    }
    Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener);
    try {
        ChatState state = ChatState.active;
        switch(chatState) {
            case active:
                state = ChatState.active;
                break;
            case composing:
                state = ChatState.composing;
                break;
            case paused:
                state = ChatState.paused;
                break;
            case inactive:
                state = ChatState.inactive;
                break;
            case gone:
                state = ChatState.gone;
                break;
        }
        Message message = new Message();
        message.addExtension(new ChatStateExtension(state));
        chat.sendMessage(message);
    } catch (XMPPException e) {
    // Ignore
    }
}
Also used : ChatState(org.jivesoftware.smackx.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.packet.ChatStateExtension) Presence(org.jivesoftware.smack.packet.Presence)

Example 7 with Presence

use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.

the class XMPPSession method updateStatus.

/**
     * @see net.sf.kraken.session.TransportSession#updateStatus(net.sf.kraken.type.PresenceType, String)
     */
@Override
public void updateStatus(PresenceType presenceType, String verboseStatus) {
    setPresenceAndStatus(presenceType, verboseStatus);
    final org.jivesoftware.smack.packet.Presence presence = constructCurrentLegacyPresencePacket();
    try {
        conn.sendPacket(presence);
    } catch (IllegalStateException e) {
        Log.debug("XMPP: Not connected while trying to change status.");
    }
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Example 8 with Presence

use of org.jivesoftware.smack.packet.Presence in project Openfire by igniterealtime.

the class XMPPSession method acceptAddContact.

/**
     * @see net.sf.kraken.session.TransportSession#acceptAddContact(JID)
     */
@Override
public void acceptAddContact(JID jid) {
    final String userID = getTransport().convertJIDToID(jid);
    Log.debug("XMPP: accept-add contact: " + userID);
    final Presence accept = new Presence(Type.subscribed);
    accept.setTo(userID);
    conn.sendPacket(accept);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Example 9 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class EnhancedDebugger method addReadPacketToTable.

/**
     * Adds the received stanza(/packet) detail to the messages table.
     *
     * @param dateFormatter the SimpleDateFormat to use to format Dates
     * @param packet        the read stanza(/packet) to add to the table
     */
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            String messageType;
            Jid from = packet.getFrom();
            String type = "";
            Icon packetTypeIcon;
            receivedPackets++;
            if (packet instanceof IQ) {
                packetTypeIcon = iqPacketIcon;
                messageType = "IQ Received (class=" + packet.getClass().getName() + ")";
                type = ((IQ) packet).getType().toString();
                receivedIQPackets++;
            } else if (packet instanceof Message) {
                packetTypeIcon = messagePacketIcon;
                messageType = "Message Received";
                type = ((Message) packet).getType().toString();
                receivedMessagePackets++;
            } else if (packet instanceof Presence) {
                packetTypeIcon = presencePacketIcon;
                messageType = "Presence Received";
                type = ((Presence) packet).getType().toString();
                receivedPresencePackets++;
            } else {
                packetTypeIcon = unknownPacketTypeIcon;
                messageType = packet.getClass().getName() + " Received";
                receivedOtherPackets++;
            }
            // Check if we need to remove old rows from the table to keep memory consumption low
            if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                messagesTable.removeRow(0);
            }
            messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetReceivedIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, "", from });
            // Update the statistics table
            updateStatistics();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Example 10 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class EnhancedDebugger method addSentPacketToTable.

/**
     * Adds the sent stanza(/packet) detail to the messages table.
     *
     * @param dateFormatter the SimpleDateFormat to use to format Dates
     * @param packet        the sent stanza(/packet) to add to the table
     */
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            String messageType;
            Jid to = packet.getTo();
            String type = "";
            Icon packetTypeIcon;
            sentPackets++;
            if (packet instanceof IQ) {
                packetTypeIcon = iqPacketIcon;
                messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
                type = ((IQ) packet).getType().toString();
                sentIQPackets++;
            } else if (packet instanceof Message) {
                packetTypeIcon = messagePacketIcon;
                messageType = "Message Sent";
                type = ((Message) packet).getType().toString();
                sentMessagePackets++;
            } else if (packet instanceof Presence) {
                packetTypeIcon = presencePacketIcon;
                messageType = "Presence Sent";
                type = ((Presence) packet).getType().toString();
                sentPresencePackets++;
            } else {
                packetTypeIcon = unknownPacketTypeIcon;
                messageType = packet.getClass().getName() + " Sent";
                sentOtherPackets++;
            }
            // Check if we need to remove old rows from the table to keep memory consumption low
            if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                messagesTable.removeRow(0);
            }
            messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetSentIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, to, "" });
            // Update the statistics table
            updateStatistics();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)89 Message (org.jivesoftware.smack.packet.Message)17 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)10 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 Jid (org.jxmpp.jid.Jid)7 Resourcepart (org.jxmpp.jid.parts.Resourcepart)7 UserPresence (jetbrains.communicator.core.users.UserPresence)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)5 Test (org.junit.Test)5 BareJid (org.jxmpp.jid.BareJid)5 EntityFullJid (org.jxmpp.jid.EntityFullJid)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 WaitFor (jetbrains.communicator.util.WaitFor)4 AccountItem (com.xabber.android.data.account.AccountItem)3 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 XMPPException (org.jivesoftware.smack.XMPPException)3