In Roster.java, I noticed that there’‘s no way I can retrieve the user’'s resources and presences. This information is stored in the Map in presenceMap.get(key). Ie, Map userPresences = (Map) presenceMap.get(key);
There’'s a method getPresences(), but that returns only the presences, I want the resources as well.
I have 2 choices:
(1) Modify fireRosterPresenceEvent() to pass the username AND resource.
I did a bit more digging, and realised that option (2) is not possible, because the fireRosterPresenceEvent() is called after removing the user presence. So, if a buddy (with multiple resources) disconnects, I cannot tell that he has disappeared (for that particular resource).
So, I had to change RosterListener.java from:
public void presenceChanged(String XMPPAddress);
to
public void presenceChanged(String XMPPAddress, String resource);
The presence objects from getPresences(String) includes the resource as the “from” field in the packet. You could use the following code as an example:
Iterator iter = roster.getPresences("user@example.com");
while (iter.hasNext()) {
Presence presence = iter.next();
System.out.println("Full JID: " + presence.getFrom());
}
For example, user1/Home and user1/Work log on. My app will receive their available presences fine. But when user1/Home logs off, the resource will be removed by the time it reaches me. The resource needs to be attached to the event for complete tracking of resources presence. I have replaced the line
Ahh, I understand the problem you’'re running into now. I think the right fix is to just make:
public void presenceChanged(String XMPPAddress);
include the resource as part of address. This change doesn’‘t violate the API spec and the current behavior is really a bug. I’'ll file a bug in the issue tracker to get this fixed for the next release.