use of org.jivesoftware.smack.packet.Presence in project Essentials by drtshock.
the class XMPPManager method connect.
private boolean connect() {
final String server = config.getString("xmpp.server");
if (server == null || server.equals("example.com")) {
LOGGER.log(Level.WARNING, "config broken for xmpp");
return false;
}
final int port = config.getInt("xmpp.port", 5222);
final String serviceName = config.getString("xmpp.servicename", server);
final String xmppuser = config.getString("xmpp.user");
final String password = config.getString("xmpp.password");
final ConnectionConfiguration connConf = new ConnectionConfiguration(server, port, serviceName);
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Connecting to xmpp server ").append(server).append(":").append(port);
stringBuilder.append(" as user ").append(xmppuser).append(".");
LOGGER.log(Level.INFO, stringBuilder.toString());
connConf.setSASLAuthenticationEnabled(config.getBoolean("xmpp.sasl-enabled", false));
connConf.setSendPresence(true);
connConf.setReconnectionAllowed(true);
connConf.setDebuggerEnabled(config.getBoolean("debug", false));
connection = new XMPPConnection(connConf);
try {
connection.connect();
connection.login(xmppuser, password, "Essentials-XMPP");
connection.sendPacket(new Presence(Presence.Type.available, "No one online.", 2, Presence.Mode.available));
connection.getRoster().setSubscriptionMode(SubscriptionMode.accept_all);
chatManager = connection.getChatManager();
chatManager.addChatListener(this);
return true;
} catch (XMPPException ex) {
LOGGER.log(Level.WARNING, "Failed to connect to server: " + server, ex);
return false;
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method getStatusText.
public String getStatusText(AccountJid account, UserJid bareAddress) {
final Occupant occupant = getOccupant(account, bareAddress);
if (occupant != null) {
return occupant.getStatusText();
}
final Presence presence = RosterManager.getInstance().getPresence(account, bareAddress);
if (presence == null) {
return null;
} else {
return presence.getStatus();
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class AvatarManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Presence)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Presence presence = (Presence) stanza;
if (presence.getType() == Presence.Type.error) {
return;
}
for (ExtensionElement packetExtension : presence.getExtensions()) {
if (packetExtension instanceof VCardUpdate) {
VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
try {
onPhotoReady(account, UserJid.from(stanza.getFrom()), vCardUpdate);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class ChatStateManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
final Resourcepart resource = stanza.getFrom().getResourceOrNull();
if (resource == null) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final UserJid bareUserJid;
try {
bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() != Type.unavailable) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
supports.remove(account.toString(), bareUserJid.toString(), resource);
} else if (stanza instanceof Message) {
boolean support = false;
for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareUserJid.getBareJid(), resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
RosterManager.onChatStateChanged(account, bareUserJid);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
}
RosterManager.onChatStateChanged(account, bareUserJid);
support = true;
break;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
return;
}
if (support) {
supports.put(account.toString(), bareUserJid.toString(), resource, true);
} else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
// Disable only if there no information about support.
supports.put(account.toString(), bareUserJid.toString(), resource, false);
}
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class VCardManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
AccountJid account = connection.getAccount();
if (stanza instanceof Presence && ((Presence) stanza).getType() != Presence.Type.error) {
Jid from = stanza.getFrom();
if (from == null) {
return;
}
Jid addressForVcard = from;
if (MUCManager.getInstance().hasRoom(account, from.asEntityBareJidIfPossible())) {
addressForVcard = from;
}
// Request vCard for new users
if (!names.containsKey(addressForVcard)) {
if (SettingsManager.connectionLoadVCard()) {
request(account, addressForVcard);
}
}
}
}
Aggregations