Search in sources :

Example 6 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method setName.

public void setName(AccountJid account, UserJid user, final String name) {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final RosterEntry entry = roster.getEntry(user.getJid().asBareJid());
    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);
    } catch (InterruptedException e) {
        LogManager.exception(LOG_TAG, e);
    }
}
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 7 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method removeGroup.

/**
 * Requests to remove group from all contacts in account.
 */
public void removeGroup(AccountJid account, String groupName) throws NetworkException {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final org.jivesoftware.smack.roster.RosterGroup group = roster.getGroup(groupName);
    if (group == null) {
        return;
    }
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            for (RosterEntry entry : group.getEntries()) {
                try {
                    group.removeEntry(entry);
                } catch (SmackException.NoResponseException e) {
                    Application.getInstance().onError(R.string.CONNECTION_FAILED);
                } catch (SmackException.NotConnectedException e) {
                    Application.getInstance().onError(R.string.NOT_CONNECTED);
                } catch (XMPPException.XMPPErrorException e) {
                    Application.getInstance().onError(R.string.XMPP_EXCEPTION);
                } catch (InterruptedException e) {
                    LogManager.exception(LOG_TAG, e);
                }
            }
        }
    });
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 8 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project Smack by igniterealtime.

the class RosterExchangeManager method send.

/**
     * Sends a roster group to userID. All the entries of the group will be sent to the 
     * target user.
     * 
     * @param rosterGroup the roster group to send
     * @param targetUserID the user that will receive the roster entries
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
    // Create a new message to send the roster
    Message msg = new Message(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    for (RosterEntry entry : rosterGroup.getEntries()) {
        rosterExchange.addRosterEntry(entry);
    }
    msg.addExtension(rosterExchange);
    XMPPConnection connection = weakRefConnection.get();
    // Send the message that contains the roster
    connection.sendStanza(msg);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 9 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry 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 10 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry 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

RosterEntry (org.jivesoftware.smack.roster.RosterEntry)13 Roster (org.jivesoftware.smack.roster.Roster)11 SmackException (org.jivesoftware.smack.SmackException)5 XMPPException (org.jivesoftware.smack.XMPPException)3 AccountItem (com.xabber.android.data.account.AccountItem)2 ConnectionItem (com.xabber.android.data.connection.ConnectionItem)2 ArrayList (java.util.ArrayList)2 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)2 AccountJid (com.xabber.android.data.entity.AccountJid)1 UserJid (com.xabber.android.data.entity.UserJid)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 Message (org.jivesoftware.smack.packet.Message)1 RosterExchange (org.jivesoftware.smackx.xroster.packet.RosterExchange)1 BareJid (org.jxmpp.jid.BareJid)1 Jid (org.jxmpp.jid.Jid)1