Element personal = contact.getChild("p");
Element presence = contact.getChild("pr");
Integer userId = Integer.parseInt(contact.getAttributeValue("id"));
//查找这个好友
Buddy buddy = context.getFetionStore().getBuddyByUserId(userId);
//这里可能是用户自己
if(buddy==null && context.getFetionUser().getUserId()==userId) {
buddy = context.getFetionUser();
}
//判断用户是不是飞信好友
if(buddy!=null) {
//好友信息改变
if(personal!=null) {
String nickname = personal.getAttributeValue("n");
String impresa = personal.getAttributeValue("i");
if(nickname!=null && nickname.length()>0) buddy.setNickName(nickname);
if(impresa!=null && impresa.length()>0) buddy.setImpresa(impresa);
String m = personal.getAttributeValue("m");
if(m!=null && m.length()>0)
buddy.setMobile(Long.parseLong(m));
String sms = personal.getAttributeValue("sms");
if(sms!=null) {
buddy.getSMSPolicy().parse(sms);
}
}
//状态改变
if(presence!=null) {
int oldpresense = buddy.getPresence().getValue();
int curpresense = Integer.parseInt(presence.getAttributeValue("b"));
BeanHelper.toBean(Presence.class, buddy.getPresence(), presence);
if(oldpresense!=curpresense) {
//注意,如果好友上线了,并且当前打开了手机聊天对话框,需要关闭这个手机聊天对话框
if(curpresense == Presence.AWAY || curpresense == Presence.BUSY ||
curpresense == Presence.ONLINE || curpresense == Presence.ROBOT ) {
ChatDialog chatDialog = this.context.getDialogFactory().findChatDialog(buddy);
if(chatDialog!=null && chatDialog instanceof BasicChatDialog) {
chatDialog.closeDialog();
}
}
//通知监听器,好友状态已经改变
this.tryFireNotifyEvent(new BuddyPresenceEvent(buddy));
}
}
//刷新数据
context.getFetionStore().flushBuddy(buddy);
logger.debug("PresenceChanged:"+buddy.toString()+" - "+buddy.getPresence());
//TODO ..这里只处理了好友状态改变,本来还应该处理其他信息改变,如好友个性签名和昵称的改变,以后添加。。
}else{
logger.warn("Unknown Buddy in PresenceChanged notify:"+userId);
}
}