Search in sources :

Example 1 with Roster

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()]));
}
Also used : Roster(org.jivesoftware.smack.roster.Roster)

Example 2 with Roster

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);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) SmackException(org.jivesoftware.smack.SmackException) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPException(org.jivesoftware.smack.XMPPException)

Example 3 with Roster

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();
            }
        });
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) MemorizingTrustManager(de.duenndns.ssl.MemorizingTrustManager) AccountRosterListener(com.xabber.android.data.roster.AccountRosterListener) Roster(org.jivesoftware.smack.roster.Roster) ExceptionLoggingCallback(org.jivesoftware.smack.parsing.ExceptionLoggingCallback)

Example 4 with Roster

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);
            }
        }
    });
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) SmackException(org.jivesoftware.smack.SmackException) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 5 with Roster

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());
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) ArrayList(java.util.ArrayList) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Aggregations

Roster (org.jivesoftware.smack.roster.Roster)10 RosterEntry (org.jivesoftware.smack.roster.RosterEntry)6 ArrayList (java.util.ArrayList)2 SmackException (org.jivesoftware.smack.SmackException)2 AccountItem (com.xabber.android.data.account.AccountItem)1 ConnectionItem (com.xabber.android.data.connection.ConnectionItem)1 AccountRosterListener (com.xabber.android.data.roster.AccountRosterListener)1 MemorizingTrustManager (de.duenndns.ssl.MemorizingTrustManager)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 XMPPException (org.jivesoftware.smack.XMPPException)1 ExceptionLoggingCallback (org.jivesoftware.smack.parsing.ExceptionLoggingCallback)1 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)1 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)1