thanks Flow, pls correction me if i'm making any mistakes. Before reconnection we can assume my current Roster has 2 entries calls oldA and oldB that belong to none groups and both has subscription="both"
After reconnection established, Roster.reload is called. a new RosterResultListener is added to handle IQ get roster packet. The new IQ roster response let's assume including 2 items let's call newA and newB, and now in RosterResultListener, we call
nonemptyResult((RosterPacket) packet, addedEntries, updatedEntries, deletedEntries);
in this method first check RosterPacket.Item ( newA and newB ) is valid or not, then call
addEntries(addedEntries, updatedEntries, deletedEntries, version, validItems);
in this method, for each validItems ( newA and newB ), get an RosterEntry and call
addUpdateEntry(addedEntries, updatedEntries, item, entry);
in this method we first got RosterEntry oldEntry = entries.put(item.getUser(), entry); then compare oldEntry ( oldA ) with params entry ( newA ). since by RosterEntry.equalsDeep method oldA and newA are the same, and both group unchanged, newA's getUser() will not be added to addedEntries nor updatedEntries.
Then this method returns back to
addEntries(addedEntries, updatedEntries, deletedEntries, version, validItems);
addedEntries, updatedEntries will not including neither newA nor newB, and we init toDelete include both newA and newB then call
toDelete.removeAll(addedEntries);
toDelete.removeAll(updatedEntries);
will do nothing since both addedEntries, updatedEntries are empty, then
for (String user : toDelete) {
deleteEntry(deletedEntries, entries.get(user));
}
newA and newB are deleted from Roster, and RosterListener's entriesDeleted is fired. So after reconnection, we have a empty Roster.
I think in
addUpdateEntry(Collection<String> addedEntries,
Collection<String> updatedEntries, RosterPacket.Item item,
RosterEntry entry)
if (!oldEntry.equalsDeep(entry) || !item.getGroupNames().equals(oldItem.getGroupNames())) {
updatedEntries.add(item.getUser());
}
can we add a boolean to indicate reconnection stituation and add ( newA and newB ) to updatedEntries.... not deeply thought. Thanks!