好友花名册
ofRoster (buddy rosters or lists)Column Name Type Length Description
rosterID | NUMBER | n/a | ID of roster (Primary Key) |
username | VARCHAR | 32 | User Name |
jid |
TEXT |
n/a |
The address of the roster entry |
sub |
NUMBER |
n/a |
The subscription status of the entry |
ask |
NUMBER |
n/a |
The ask status of the entry |
recv |
NUMBER |
n/a |
Flag indicating the entry is a roster request that was received |
nick |
VARCHAR |
255 |
The nickname assigned to this roster entry
|
字段的具体分析:
askstatus
-1— 没有挂起的添加好友请求。
The roster item has no pending subscription requests.
0— 有挂起的添加好友请求。
The roster item has been asked for permission to subscribe to its presence but no response has been received.
1— 估计是有没有回复的删除请求吧
The roster owner has asked the roster item to be unsubscribed from its presence notifications but hasn't yet received confi rmation.
recvstatus
-1— 已经回复添加好友请求
There are no subscriptions that have been received but not presented to the user.
1— 接收到好友请求但是没有给好友回复
The server has received a subscribe request, but has not forwarded it to the user.
2— 估计是没有回复删除请求吧
The server has received an unsubscribe request, but has not forwarded it to the user.
substatus
-1— 应该删除这个好友
Indicates that the roster item should be removed.
0— 没有建立好友关系
No subscription is established.
1— 用户已经发出好友请求
The roster owner has a subscription to the roster item’s presence.
2— 收到好友请求并且加对方好友
The roster item has a subscription to the roster owner’s presence.
3— 好友已经相互添加
The roster item and the owner have a mutual subscription.
代码操作:
PacketListener myListener = new PacketListener() {
public void processPacket(Packet packet) {
if(packet instanceof Message) {
Message message = (Message) packet;
String type = message.getType().toString();
if(type.equals("chat")) {
//接收消息
if(message.getBody()!=null){
//保存信息到客户端数据库
}
}
}
} else if(packet instanceof Presence) {
Presence presence = (Presence) packet;
String type = presence.getType().toString();
boolean b= TalkService.this.roster.contains(packet.getFrom());
Log.i(tag, b+"");
Roster roster = connection.getRoster();
RosterEntry rosterEntry = roster.getEntry(presence.getFrom());
String itemType="";
if(rosterEntry!=null){
Log.e(tag, "PacketListener Presence: rosterEntry.getName()= "+rosterEntry.getName()+
" - rosterEntry.getUser()="+rosterEntry.getUser()+
" - rosterEntry.getStatus()="+rosterEntry.getStatus()+
" -rosterEntry.getType()= "+rosterEntry.getType());
itemType=rosterEntry.getType().toString();
}
Log.e(tag, "itemType=="+itemType);
if(type.equals("subscribe")) {//我收到对方的加好友的请求
//添加好友请求
FriendRelationParam param = new FriendRelationParam();
TalkCallback callback = new TalkCallback();
callback.from = getUId(presence.getFrom());
callback.to = getUId(presence.getTo());
try {
param.callbackStr = callback.toJsonObject().toString();
} catch (Exception e) {
e.printStackTrace();
}
param.userId = Long.parseLong(callback.to);
param.friendUid = Long.parseLong(callback.from);
startFriendRelation(param);
if("none".equals(itemType)){//收到对方的加好友的请求
Log.i(tag, "type="+type+" 我收到对方的加好友的请求");
}
if("to".equals(itemType)){//我加对方好友后,对方同意,给我发回的交友请求
Log.i(tag, "type="+type+" 我加对方好友后,对方同意,给我发回的交友请求");
}
}else if("subscribed".equals(type)){//对方同意加我为好友
if("both".equals(itemType)){//双方互为好友关系建立
Log.i(tag, "type="+type+" 双方互为好友关系建立!");
}
Log.e("TalkService"+Thread.currentThread().getName(), presence.getFrom()+"同意了我["+packet.getTo()+"]的加好友请求 ");
}else if(type.equals("unsubscribe")) {//对方发起了把我删除了||或者拒绝 //拒绝的时候只会走这A
if("none".equals(itemType)){//拒绝
Log.i(tag, "type="+type+" 我被拒绝!!!");
}
if("to".equals(itemType)){//我收到被对方删除
Log.i(tag, "type="+type+" 我收到被对方删除");
}
}else if(type.equals("unsubscribed")) {//对方把我删除了 //删除的时候 会走A,同时再走一次这
if("none".equals(itemType)){// 我被删除 ,双方关系解除**************************
Log.i(tag, "type="+type+" 我被删除的!!!");
}
}else if(type.equals("available")) {//对方告诉我他在线
// presence = new Presence(Presence.Type.available);
// presence.setTo(presence.getFrom());
// connection.sendPacket(presence);
}
}else if(packet instanceof AuthMechanism) {
}
}
};