{
Element el = (Element)iter.next();
Element cIdEl = XmlUtils.findChild(el, "contactId");
MsnContactImpl contact = new MsnContactImpl(contactList);
String contactId = XmlUtils.getText(cIdEl).trim();
contact.setId(contactId);
Element contactInfoEl = XmlUtils.findChild(el, "contactInfo");
Element contactTypeEl = XmlUtils.findChild(contactInfoEl, "contactType");
String cType = XmlUtils.getText(contactTypeEl);
if(cType.equalsIgnoreCase("me"))
{
Element contactDisplayNameEl =
XmlUtils.findChild(contactInfoEl, "displayName");
myDisplayName = XmlUtils.getText(contactDisplayNameEl);
continue;
}
/* ignore non-messenger contacts */
Element isMessengerUserEl = XmlUtils.findChild(contactInfoEl, "isMessengerUser");
boolean isMessengerUser = Boolean.parseBoolean(XmlUtils.getText(isMessengerUserEl));
if(!isMessengerUser)
continue;
Element emailNameEl = XmlUtils.findChild(contactInfoEl, "passportName");
String email = XmlUtils.getText(emailNameEl);
if(email == null)
{
// new
Element isMessengerEnabledEl =
XmlUtils.findChildByChain(contactInfoEl,
new String[]{"emails", "ContactEmail", "isMessengerEnabled"});
if(isMessengerEnabledEl == null ||
!Boolean.parseBoolean(XmlUtils.getText(isMessengerEnabledEl)))
continue;
Element emailEl = XmlUtils.findChildByChain(contactInfoEl,
new String[]{"emails", "ContactEmail", "email"});
if(emailEl == null)
continue;
email = XmlUtils.getText(emailEl);
if(email == null)
continue;
}
contact.setEmail(Email.parseStr(email));
Element groupsEl = XmlUtils.findChild(contactInfoEl, "groupIds");
if(groupsEl != null)
{
List grIdsEls = XmlUtils.findChildren(groupsEl, "guid");
Iterator i = grIdsEls.iterator();
while (i.hasNext())
{
Element guid = (Element)i.next();
contact.addBelongGroup(XmlUtils.getText(guid).trim());
}
}
Element displayNameEl = XmlUtils.findChild(contactInfoEl, "displayName");
String displayName = XmlUtils.getText(displayNameEl);
contact.setFriendlyName(displayName);
contact.setDisplayName(displayName);
// telephone ??
// list number is sum of all lists that the contact is in.
int listNumber = 0;
Iterator i = membersRoles.entrySet().iterator();
while (i.hasNext())
{
Entry e = (Entry)i.next();
MemberRole mr = (MemberRole)e.getValue();
if(mr.getMembers().contains(email))
{
listNumber += mr.list.getListId();
}
}
// something is wrong, contact in noone list
if(listNumber == 0)
continue;
contact.setListNumber(listNumber);
if(contact.isInList(MsnList.AL))
contact.setInList(MsnList.FL, true);
// Fix for error 241 (contact in allow and blocked list)
if(contact.isInList(MsnList.AL) && contact.isInList(MsnList.BL))
{
contact.setInList(MsnList.FL, false);
contact.setInList(MsnList.AL, false);
contact.setInList(MsnList.PL, false);
}
/* It seems that such fix doesn't work as expected,
* I leave it there anyway, but I see a l=5 in other clients raw log!
* There's other strange 241 error I got that should be solved with the code below
* (James Lopez - BLuEGoD)
*/
if((listNumber | MsnList.RL.getListId())==MsnList.RL.getListId())
contact.setInList(MsnList.PL, true);
contactList.addContact(contact);
}
}