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
}
}
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.");
}
}
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);
}
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();
}
});
}
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();
}
});
}
Aggregations