use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.
the class ConnectionItem method disconnect.
/**
* Starts disconnection in another thread.
*/
protected void disconnect(final ConnectionThread connectionThread) {
Thread thread = new Thread("Disconnection thread for " + this) {
@Override
public void run() {
AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection != null)
try {
xmppConnection.disconnect();
} catch (RuntimeException e) {
// connectionClose() in smack can fail.
}
}
};
thread.setPriority(Thread.MIN_PRIORITY);
thread.setDaemon(true);
thread.start();
}
use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.
the class ClientStateManager method sendClientState.
protected static void sendClientState(PlainStreamElement element) {
AccountManager accountManager = AccountManager.getInstance();
for (String accountName : accountManager.getAccounts()) {
AccountItem account = accountManager.getAccount(accountName);
if (account == null) {
continue;
}
ConnectionThread connectionThread = account.getConnectionThread();
if (connectionThread == null) {
continue;
}
AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
continue;
}
if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
try {
xmppConnection.send(element);
} catch (SmackException.NotConnectedException e) {
// not connected
}
}
}
use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.
the class VCardManager method saveVCard.
public void saveVCard(final String account, final VCard vCard) {
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null) {
onVCardSaveFailed(account);
return;
}
final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(xmppConnection);
final Thread thread = new Thread("Save vCard for account " + account) {
@Override
public void run() {
boolean isSuccess = true;
xmppConnection.setPacketReplyTimeout(120000);
vCardSaveRequests.add(account);
try {
vCardManager.saveVCard(vCard);
String avatarHash = vCard.getAvatarHash();
if (avatarHash == null) {
avatarHash = AvatarManager.EMPTY_HASH;
}
PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException e) {
LogManager.w(this, "Error saving vCard: " + e.getMessage());
isSuccess = false;
}
vCardSaveRequests.remove(account);
xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
final boolean finalIsSuccess = isSuccess;
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalIsSuccess) {
onVCardSaveSuccess(account);
} else {
onVCardSaveFailed(account);
}
}
});
}
};
thread.start();
}
use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.
the class RosterManager method getRoster.
@Nullable
private Roster getRoster(String account) {
final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return null;
}
final ConnectionThread connectionThread = accountItem.getConnectionThread();
if (connectionThread == null) {
return null;
}
final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
return null;
}
return Roster.getInstanceFor(xmppConnection);
}
Aggregations