我正在使用 asmack 8-0.8.3。
当我的联系人移动到“可用”时,我没有收到关于状态更改的消息。如果一个联系人从“可用”变为“dnd”,我确实会收到一条消息。但反之则不然。
Contact passes: "available" --> "dnd" --> "available" --> "dnd"
I receive: Presence{dnd} Presence{dnd}
而我希望在 2 dnd 之间收到 Presence 更新 {available}。
由于我收到除了“可用”之外的状态更新,我想我的听众工作正常。另外我想我正确订阅了我的联系人的存在......
private class FriendListener implements RosterListener {
public void entriesAdded(Collection<String> addresses) { }
public void entriesUpdated(Collection<String> addresses) { }
public void entriesDeleted(Collection<String> addresses) { }
public void presenceChanged(Presence presence) {
String fromUserID = StringUtils.parseBareAddress(presence.getFrom());
System.out.println(
"Presence changed: " + fromUserID +
" Presence=" + presence.toString() +
" Type=" + presence.getType().toString() +
" Mode=" + presence.getMode().toString()
);
mainCallback_.updatePresenceFriend(fromUserID, presence);
}
}
public void subscribe(String friendID, String friendName) {
Presence presence = new Presence(Presence.Type.subscribe);
connection.sendPacket(presence);
RosterPacket rosterPacket = new RosterPacket();
rosterPacket.setType(IQ.Type.SET);
Item item = new Item(friendID, friendName);
item.setItemType(RosterPacket.ItemType.both);
rosterPacket.addRosterItem(item);
connection.sendPacket(rosterPacket);
System.out.println("Send subscribe to " + friendID);
subscribedUsers.add(friendID);
}