List list = XMLHelper.findAll(event, "/event/contacts/buddies/*buddy");
Iterator it = list.iterator();
while(it.hasNext()) {
Element e = (Element) it.next();
String uri = e.getAttributeValue("uri");
final Buddy buddy = context.getFetionStore().getBuddyByUri(uri);
if(buddy!=null) {
//检查用户关系的变化
Relation relation = ParseHelper.parseRelation(e.getAttributeValue("relation-status"));
//如果当前好友关系是没有确认,而返回的好友是确认了,表明好友同意了你添加好友的请求
if(relation==Relation.BUDDY && buddy.getRelation()!=Relation.BUDDY) {
//这里还需要获取好友的详细信息
SipcRequest request = dialog.getMessageFactory().createGetContactInfoRequest(buddy.getUri());
request.setResponseHandler(new GetContactInfoResponseHandler(context, dialog, ((Buddy) buddy),null));
dialog.process(request);
}else if(relation==Relation.DECLINED) { //对方拒绝了请求
logger.debug("buddy declined your buddy request:"+buddy.getDisplayName());
this.tryFireNotifyEvent(new BuddyConfirmedEvent( buddy, false)); //通知监听器
}else {}
//buddy.setUserId(Integer.parseInt(e.getAttributeValue("user-id")));
buddy.setRelation(relation);
context.getFetionStore().flushBuddy(buddy);
}
}
}