Search in sources :

Example 26 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)

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

Example 28 with RosterEntry

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

the class RosterManager method getRosterContact.

/**
     * @param account
     * @param user
     * @return <code>null</code> can be returned.
     */
public RosterContact getRosterContact(String account, String user) {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return null;
    }
    final RosterEntry entry = roster.getEntry(user);
    if (entry == null) {
        return null;
    } else {
        return convertRosterEntryToRosterContact(account, roster, entry);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 29 with RosterEntry

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

the class RosterManager method setGroups.

public void setGroups(String account, String bareAddress, Collection<String> groups) throws NetworkException {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final RosterEntry entry = roster.getEntry(bareAddress);
    if (entry == null) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);
    RosterPacket.Item item = new RosterPacket.Item(bareAddress, entry.getName());
    for (String group : groups) {
        item.addGroupName(group);
    }
    packet.addRosterItem(item);
    ConnectionManager.getInstance().sendStanza(account, packet);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionItem(com.xabber.android.data.connection.ConnectionItem) Roster(org.jivesoftware.smack.roster.Roster) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 30 with RosterEntry

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

the class ContactListAssistantPlugin method removeContactItem.

public boolean removeContactItem(ContactGroup contactGroup, ContactItem item) {
    if (contactGroup.isSharedGroup()) {
        return false;
    }
    if (contactGroup.isUnfiledGroup()) {
        contactGroup.removeContactItem(item);
        contactGroup.fireContactGroupUpdated();
        return true;
    }
    // Remove entry from Roster Group
    Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    RosterEntry entry = roster.getEntry(item.getJID());
    RosterGroup rosterGroup = null;
    for (RosterGroup group : roster.getGroups()) {
        if (group.getName().equals(contactGroup.getGroupName())) {
            try {
                rosterGroup = group;
                group.removeEntry(entry);
            } catch (XMPPException | SmackException e1) {
                return false;
            }
        }
    }
    if (rosterGroup == null) {
        return false;
    }
    if (!rosterGroup.contains(entry)) {
        contactGroup.removeContactItem(item);
        // Updating group title
        contactGroup.fireContactGroupUpdated();
        return true;
    }
    return false;
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) SmackException(org.jivesoftware.smack.SmackException) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPException(org.jivesoftware.smack.XMPPException) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Aggregations

RosterEntry (org.jivesoftware.smack.roster.RosterEntry)45 Roster (org.jivesoftware.smack.roster.Roster)35 RosterGroup (org.jivesoftware.smack.roster.RosterGroup)17 SmackException (org.jivesoftware.smack.SmackException)14 Presence (org.jivesoftware.smack.packet.Presence)13 XMPPException (org.jivesoftware.smack.XMPPException)12 IOException (java.io.IOException)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)4 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)3 AccountItem (com.xabber.android.data.account.AccountItem)2 ConnectionItem (com.xabber.android.data.connection.ConnectionItem)2 java.awt (java.awt)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 KeyEvent (java.awt.event.KeyEvent)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 javax.swing (javax.swing)2 Icon (javax.swing.Icon)2