Fixes processing jabber presences and displaying online contacts even if slowly initializing the contactlist.

cusax-fix
Damian Minkov 14 years ago
parent 2d3ba8ca65
commit 9b808b2b7c

@ -897,9 +897,20 @@ void firePresenceStatusChanged(Presence presence)
/**
* Manage changes of statuses by resource.
*/
private class ContactChangesListener
class ContactChangesListener
implements RosterListener
{
/**
* Store events for later processing, used when
* initializing contactlist.
*/
private boolean storeEvents = false;
/**
* Stored presences for later processing.
*/
private List<Presence> storedPresences = null;
/**
* Map containing all statuses for a userID.
*/
@ -936,6 +947,29 @@ public void presenceChanged(Presence presence)
firePresenceStatusChanged(presence);
}
/**
* Sets store events to true.
*/
void storeEvents()
{
this.storedPresences = new ArrayList<Presence>();
this.storeEvents = true;
}
/**
* Process stored presences.
*/
void processStoredEvents()
{
storeEvents = false;
for(Presence p : storedPresences)
{
firePresenceStatusChanged(p);
}
storedPresences.clear();
storedPresences = null;
}
/**
* Fires the status change, respecting resource priorities.
*
@ -943,6 +977,12 @@ public void presenceChanged(Presence presence)
*/
void firePresenceStatusChanged(Presence presence)
{
if(storeEvents && storedPresences != null)
{
storedPresences.add(presence);
return;
}
try
{
String userID

@ -745,20 +745,23 @@ public void moveContact(ContactJabberImpl contact,
* roster that this list is to use for retrieving
* server stored information
*/
void init(RosterListener presenceChangeListener)
void init(OperationSetPersistentPresenceJabberImpl.ContactChangesListener
presenceChangeListener)
{
this.roster = jabberProvider.getConnection().getRoster();
presenceChangeListener.storeEvents();
this.roster.addRosterListener(presenceChangeListener);
this.roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
initRoster();
presenceChangeListener.processStoredEvents();
rosterChangeListener = new ChangeListener();
this.roster.addRosterListener(rosterChangeListener);
}
/**
* Cleanups references and listers.
* Cleanups references and listeners.
*/
void cleanup()
{
@ -861,8 +864,7 @@ private void initRoster()
if(group == null)
{
// create the group as it doesn't exist
ContactGroupJabberImpl newGroup =
new ContactGroupJabberImpl(
ContactGroupJabberImpl newGroup = new ContactGroupJabberImpl(
item, item.getEntries().iterator(), this, true);
rootGroup.addSubGroup(newGroup);
@ -870,6 +872,18 @@ private void initRoster()
//tell listeners about the added group
fireGroupEvent(newGroup
, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
// if presence was already received it,
// we must check & dispatch it
if(roster != null)
{
Iterator<Contact> cIter = newGroup.contacts();
while(cIter.hasNext())
{
parentOperationSet.firePresenceStatusChanged(
roster.getPresence(cIter.next().getAddress()));
}
}
}
else
{
@ -989,6 +1003,15 @@ void fireContactResolved( ContactGroup parentGroup,
return;
}
// if we are already registered(roster != null) and we are currently
// creating the contact list, presences maybe already received
// before we have created the contacts, so lets check
if(roster != null)
{
parentOperationSet.firePresenceStatusChanged(
roster.getPresence(contact.getAddress()));
}
// dispatch
parentOperationSet.fireSubscriptionEvent(contact, parentGroup,
SubscriptionEvent.SUBSCRIPTION_RESOLVED);

Loading…
Cancel
Save