diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 358a07951..f57ad50c4 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -98,6 +98,7 @@ public class Roster { private XMPPConnection connection; private Map groups; + private List entries; private List unfiledEntries; private List rosterListeners; private Map presenceMap; @@ -116,6 +117,7 @@ public class Roster { this.connection = connection; groups = new Hashtable(); unfiledEntries = new ArrayList(); + entries = new ArrayList(); rosterListeners = new ArrayList(); presenceMap = new HashMap(); // Listen for any roster packets. @@ -188,7 +190,10 @@ public class Roster { } /** - * Creates a new group. + * Creates a new group.

+ * + * Note: you must add at least one entry to the group for the group to be kept + * after a logout/login. This is due to the way that XMPP stores group information. * * @param name the name of the group. * @return a new group. @@ -210,7 +215,7 @@ public class Roster { * * @param user the user. * @param name the nickname of the user. - * @param groups the list of groups entry will belong to, or null if the + * @param groups the list of group names the entry will belong to, or null if the * the roster entry won't belong to a group. */ public void createEntry(String user, String name, String [] groups) throws XMPPException { @@ -283,15 +288,28 @@ public class Roster { } // Add the roster unfiled entries to the new RosterExchange synchronized (unfiledEntries) { - allEntries.add(unfiledEntries); + allEntries.addAll(unfiledEntries); } return allEntries.iterator(); } /** - * Returns an Iterator for the roster entries that haven't been assigned to any groups. + * Returns a count of the unfiled entries in the roster. An unfiled entry is + * an entry that doesn't belong to any groups. * - * @return an iterator the roster entries that haven't been filed into groups. + * @return the number of unfiled entries in the roster. + */ + public int getUnfiledEntryCount() { + synchronized (unfiledEntries) { + return unfiledEntries.size(); + } + } + + /** + * Returns an Iterator for the unfiled roster entries. An unfiled entry is + * an entry that doesn't belong to any groups. + * + * @return an iterator the unfiled roster entries. */ public Iterator getUnfiledEntries() { synchronized (unfiledEntries) { @@ -348,9 +366,9 @@ public class Roster { } /** - * Fires roster listeners. + * Fires roster changed event to roster listeners. */ - private void fireRosterListeners() { + private void fireRosterChangedEvent() { RosterListener [] listeners = null; synchronized (rosterListeners) { listeners = new RosterListener[rosterListeners.size()]; @@ -361,6 +379,20 @@ public class Roster { } } + /** + * Fires roster presence changed event to roster listeners. + */ + private void fireRosterPresenceEvent(String user) { + RosterListener [] listeners = null; + synchronized (rosterListeners) { + listeners = new RosterListener[rosterListeners.size()]; + rosterListeners.toArray(listeners); + } + for (int i=0; i