use of org.jivesoftware.smack.roster.Roster in project xabber-android by redsolution.
the class RosterManager method createContact.
/**
* Requests to create new contact.
*
* @param account
* @param bareAddress
* @param name
* @param groups
* @throws NetworkException
*/
public void createContact(String account, String bareAddress, String name, Collection<String> groups) throws SmackException.NotLoggedInException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
final Roster roster = getRoster(account);
if (roster == null) {
return;
}
roster.createEntry(bareAddress, name, groups.toArray(new String[groups.size()]));
}
use of org.jivesoftware.smack.roster.Roster in project xabber-android by redsolution.
the class RosterManager method setName.
public void setName(String account, String bareAddress, final String name) {
final Roster roster = getRoster(account);
if (roster == null) {
return;
}
final RosterEntry entry = roster.getEntry(bareAddress);
if (entry == null) {
return;
}
try {
entry.setName(name.trim());
} catch (SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
}
}
use of org.jivesoftware.smack.roster.Roster in project xabber-android by redsolution.
the class ConnectionThread method onReady.
private void onReady(XMPPTCPConnectionConfiguration.Builder builder) {
builder.setSecurityMode(tlsMode.getSecurityMode());
builder.setCompressionEnabled(compression);
builder.setSendPresence(false);
try {
if (SettingsManager.securityCheckCertificate()) {
SSLContext sslContext = SSLContext.getInstance("TLS");
MemorizingTrustManager mtm = new MemorizingTrustManager(Application.getInstance());
sslContext.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom());
builder.setCustomSSLContext(sslContext);
builder.setHostnameVerifier(mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));
} else {
TLSUtils.acceptAllCertificates(builder);
TLSUtils.disableHostnameVerificationForTlsCertificicates(builder);
}
} catch (NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}
setUpSASL();
xmppConnection = new XMPPTCPConnection(builder.build());
xmppConnection.addAsyncStanzaListener(this, ACCEPT_ALL);
xmppConnection.addConnectionListener(this);
// by default Smack disconnects in case of parsing errors
xmppConnection.setParsingExceptionCallback(new ExceptionLoggingCallback());
AccountRosterListener rosterListener = new AccountRosterListener(((AccountItem) connectionItem).getAccount());
final Roster roster = Roster.getInstanceFor(xmppConnection);
roster.addRosterListener(rosterListener);
roster.addRosterLoadedListener(rosterListener);
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
org.jivesoftware.smackx.ping.PingManager.getInstanceFor(xmppConnection).registerPingFailedListener(this);
connectionItem.onSRVResolved(this);
final String password = OAuthManager.getInstance().getPassword(protocol, token);
if (password != null) {
runOnConnectionThread(new Runnable() {
@Override
public void run() {
connect(password);
}
});
} else {
runOnConnectionThread(new Runnable() {
@Override
public void run() {
passwordRequest();
}
});
}
}
use of org.jivesoftware.smack.roster.Roster in project xabber-android by redsolution.
the class RosterManager method removeContact.
/**
* Requests contact removing.
*
*/
public void removeContact(String account, String bareAddress) {
final Roster roster = getRoster(account);
if (roster == null) {
return;
}
final RosterEntry entry = roster.getEntry(bareAddress);
if (entry == null) {
return;
}
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
try {
roster.removeEntry(entry);
} catch (SmackException.NotLoggedInException | SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
}
}
});
}
use of org.jivesoftware.smack.roster.Roster in project xabber-android by redsolution.
the class RosterManager method updateContacts.
void updateContacts() {
Collection<RosterContact> newRosterContacts = new ArrayList<>();
for (String account : AccountManager.getInstance().getAccounts()) {
final Roster roster = RosterManager.getInstance().getRoster(account);
if (roster == null) {
continue;
}
final Set<RosterEntry> entries = roster.getEntries();
for (RosterEntry rosterEntry : entries) {
final RosterContact contact = convertRosterEntryToRosterContact(account, roster, rosterEntry);
newRosterContacts.add(contact);
}
}
allRosterContacts = newRosterContacts;
LogManager.i(this, "updateContacts: " + allRosterContacts.size());
}
Aggregations