Roster and Presence at startup

Hi

I have encountered a timing issue with Smack 1.4.1 and Messenger 2.0.1.

In XmppConnection.login(), it sends the Roster IQ followed by the Presence IQ after successfully logging on:

// Create the roster.

this.roster = new Roster(this);

roster.reload();

// Set presence to online.

packetWriter.sendPacket(new Presence(Presence.Type.AVAILABLE));

In my client code, this is what I do for logging on:

xmppConnection.login(userName, password, resource);

xmppConnection.getRoster().addRosterListener(this);

Roster roster = xmppConnection.getRoster();

populateRosterJTree(roster);

Now, before I finish populating the JTree, I have already received a Presence event from the server (a buddy is online), which causes the JTree to miss that presence.

I am hoping there’'s a way to finish populating the JTree before sending out the presence IQ, ie:

xmppConnection.loginDoNotSendPresence(userName, password, resource); // Do not send the presence packet

xmppConnection.getRoster().addRosterListener(this);

Roster roster = xmppConnection.getRoster();

populateRosterJTree(roster);

xmppConnection.sendPacket(new Presence(Presence.Type.AVAILABLE));

Or any other ideas would be appreciated.

Regards

Keith

Just to note that this only happens because I have a large roster list and thus takes time to populate the JTree.

It also happens occasionally, if Messenger decides to send the Presence immediately after the Roster packet. Sometimes it takes a while, so the JTree would have been populated.

This is not a major issue, as I can always issue another presence packet after creating the JTree.

Keith

Hi

More debugging shows that:

xmppConnection.sendPacket(new Presence(Presence.Type.AVAILABLE));

Does not cause the presence of the buddies to be resent, so my suggested flow will not work.

I will have to figure out another way to handle this.

Keith

Ok, I have solved it at the application level. My solution uses a similar approach to the getRoster() method in XmppConnection. Ie if the JTree is not populated, it waits for it to be populated before dispatching the presenceChanged() event.

Regards

Keith