mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-15 03:52:05 +01:00
Fixes problems when waiting a few seconds when the roster has not been initialized yet
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2202 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
d78e1d3e59
commit
1fa6a8e9fb
1 changed files with 35 additions and 47 deletions
|
@ -208,9 +208,6 @@ public class Roster {
|
||||||
* @return a new group.
|
* @return a new group.
|
||||||
*/
|
*/
|
||||||
public RosterGroup createGroup(String name) {
|
public RosterGroup createGroup(String name) {
|
||||||
if (!rosterInitialized) {
|
|
||||||
waitUntilInitialized();
|
|
||||||
}
|
|
||||||
synchronized (groups) {
|
synchronized (groups) {
|
||||||
if (groups.containsKey(name)) {
|
if (groups.containsKey(name)) {
|
||||||
throw new IllegalArgumentException("Group with name " + name + " alread exists.");
|
throw new IllegalArgumentException("Group with name " + name + " alread exists.");
|
||||||
|
@ -338,6 +335,9 @@ public class Roster {
|
||||||
* @return the number of unfiled entries in the roster.
|
* @return the number of unfiled entries in the roster.
|
||||||
*/
|
*/
|
||||||
public int getUnfiledEntryCount() {
|
public int getUnfiledEntryCount() {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
waitUntilInitialized();
|
||||||
|
}
|
||||||
synchronized (unfiledEntries) {
|
synchronized (unfiledEntries) {
|
||||||
return unfiledEntries.size();
|
return unfiledEntries.size();
|
||||||
}
|
}
|
||||||
|
@ -350,6 +350,9 @@ public class Roster {
|
||||||
* @return an iterator the unfiled roster entries.
|
* @return an iterator the unfiled roster entries.
|
||||||
*/
|
*/
|
||||||
public Iterator getUnfiledEntries() {
|
public Iterator getUnfiledEntries() {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
waitUntilInitialized();
|
||||||
|
}
|
||||||
synchronized (unfiledEntries) {
|
synchronized (unfiledEntries) {
|
||||||
return Collections.unmodifiableList(new ArrayList(unfiledEntries)).iterator();
|
return Collections.unmodifiableList(new ArrayList(unfiledEntries)).iterator();
|
||||||
}
|
}
|
||||||
|
@ -366,11 +369,14 @@ public class Roster {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
waitUntilInitialized();
|
||||||
|
}
|
||||||
// Roster entries never include a resource so remove the resource
|
// Roster entries never include a resource so remove the resource
|
||||||
// if it's a part of the XMPP address.
|
// if it's a part of the XMPP address.
|
||||||
user = StringUtils.parseBareAddress(user);
|
user = StringUtils.parseBareAddress(user);
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator i=getFiledEntriesList().iterator(); i.hasNext(); ) {
|
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
||||||
RosterEntry entry = (RosterEntry)i.next();
|
RosterEntry entry = (RosterEntry)i.next();
|
||||||
if (entry.getUser().equals(user)) {
|
if (entry.getUser().equals(user)) {
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -390,11 +396,14 @@ public class Roster {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
waitUntilInitialized();
|
||||||
|
}
|
||||||
// Roster entries never include a resource so remove the resource
|
// Roster entries never include a resource so remove the resource
|
||||||
// if it's a part of the XMPP address.
|
// if it's a part of the XMPP address.
|
||||||
user = StringUtils.parseBareAddress(user);
|
user = StringUtils.parseBareAddress(user);
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator i=getFiledEntriesList().iterator(); i.hasNext(); ) {
|
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
||||||
RosterEntry entry = (RosterEntry)i.next();
|
RosterEntry entry = (RosterEntry)i.next();
|
||||||
if (entry.getUser().equals(user)) {
|
if (entry.getUser().equals(user)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -434,40 +443,15 @@ public class Roster {
|
||||||
* @return an iterator for all roster groups.
|
* @return an iterator for all roster groups.
|
||||||
*/
|
*/
|
||||||
public Iterator getGroups() {
|
public Iterator getGroups() {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
waitUntilInitialized();
|
||||||
|
}
|
||||||
synchronized (groups) {
|
synchronized (groups) {
|
||||||
List groupsList = Collections.unmodifiableList(new ArrayList(getGroupsMap().values()));
|
List groupsList = Collections.unmodifiableList(new ArrayList(groups.values()));
|
||||||
return groupsList.iterator();
|
return groupsList.iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns entries in the roster that belong to at least one group.<p>
|
|
||||||
*
|
|
||||||
* Since the user can ask for the entries after calling login, it's possible that the
|
|
||||||
* entries were not received yet. Therefore, the method call won't return until the
|
|
||||||
* roster has been initialized or two seconds has elapsed.
|
|
||||||
*
|
|
||||||
* @return filed entries in the roster.
|
|
||||||
*/
|
|
||||||
private List getFiledEntriesList() {
|
|
||||||
waitUntilInitialized();
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the roster groups.<p>
|
|
||||||
*
|
|
||||||
* Since the user can ask for the groups after calling login, it's possible that the
|
|
||||||
* groups were not received yet. Therefore, the method call won't return until the
|
|
||||||
* roster has been initialized or two seconds has elapsed.
|
|
||||||
*
|
|
||||||
* @return filed entries in the roster.
|
|
||||||
*/
|
|
||||||
private Map getGroupsMap() {
|
|
||||||
waitUntilInitialized();
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits until the roster has been initialized or 2 seconds has elapsed. It is required to
|
* Waits until the roster has been initialized or 2 seconds has elapsed. It is required to
|
||||||
* wait before the user can make use of the roster when for example this is the first time
|
* wait before the user can make use of the roster when for example this is the first time
|
||||||
|
@ -724,10 +708,12 @@ public class Roster {
|
||||||
|
|
||||||
// Find the list of groups that the user currently belongs to.
|
// Find the list of groups that the user currently belongs to.
|
||||||
List currentGroupNames = new ArrayList();
|
List currentGroupNames = new ArrayList();
|
||||||
|
if (rosterInitialized) {
|
||||||
for (Iterator j = entry.getGroups(); j.hasNext(); ) {
|
for (Iterator j = entry.getGroups(); j.hasNext(); ) {
|
||||||
RosterGroup group = (RosterGroup)j.next();
|
RosterGroup group = (RosterGroup)j.next();
|
||||||
currentGroupNames.add(group.getName());
|
currentGroupNames.add(group.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the packet is not of the type REMOVE then add the entry to the groups
|
// If the packet is not of the type REMOVE then add the entry to the groups
|
||||||
if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
|
if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
|
||||||
|
@ -757,6 +743,7 @@ public class Roster {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through any groups that remain and remove the entries.
|
// Loop through any groups that remain and remove the entries.
|
||||||
|
if (rosterInitialized) {
|
||||||
for (int n=0; n<currentGroupNames.size(); n++) {
|
for (int n=0; n<currentGroupNames.size(); n++) {
|
||||||
String groupName = (String)currentGroupNames.get(n);
|
String groupName = (String)currentGroupNames.get(n);
|
||||||
RosterGroup group = getGroup(groupName);
|
RosterGroup group = getGroup(groupName);
|
||||||
|
@ -768,12 +755,13 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Fire event for roster listeners.
|
|
||||||
fireRosterChangedEvent();
|
|
||||||
|
|
||||||
// Mark the roster as initialized.
|
// Mark the roster as initialized.
|
||||||
rosterInitialized = true;
|
rosterInitialized = true;
|
||||||
|
|
||||||
|
// Fire event for roster listeners.
|
||||||
|
fireRosterChangedEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue