public void processPacket(Packet packet) {
if (!BuddyList.getInstance().checkConnection()) {
return;
}
final Presence presence = (Presence) packet;
String from = presence.getFrom();
ParsedBuddyInfo info = new ParsedBuddyInfo(from);
final String userId = info.getUserId();
final String resource = info.getResource();
final String server = info.getServer();
// if the user is blocked, ignore this packet
if (BuddyList.getInstance().getBlockedUsers().containsKey(userId)) {
return;
}
// if this is a groupchat packet, then we don't care about it in this
// class
if (BuddyList.getInstance().getTabFrame() != null
&& (BuddyList.getInstance().getTabFrame().getChatPanel(userId) != null || BuddyList.getInstance().getTabFrame().getChatPanel(from) != null)) {
return;
}
// if they are trying to subscribe, as if we want to let them subscribe
if (presence.getType() == Presence.Type.SUBSCRIBE) {
requestSubscription(userId);
return;
}
// beyond this point, we don't care about anything but online and
// offline packets
if (presence.getType() != Presence.Type.AVAILABLE
&& presence.getType() != Presence.Type.UNAVAILABLE) {
return;
}
final BuddyStatus buddy = BuddyList.getInstance()
.getBuddyStatus(userId);
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
boolean isSelf = false;
if (buddy.getUser().equals(
BuddyList.getInstance().getConnection().getUser()
.replaceAll("/.*", ""))) {
isSelf = true;
}
// if it's unavailable, check to see if they have any resources
// still online
// if they do, set the packet to available, and minus one
// resource
if (presence.getType() == Presence.Type.UNAVAILABLE) {
buddy.removeResource(resource);
if (buddy.size() > 0) {
presence.setType(Presence.Type.AVAILABLE);
}
} else {
int priority = presence.getPriority();
if (priority < 0) {
priority = 0;
}
buddy.addResource(resource, priority, presence.getMode(),
presence.getStatus());
}
performPresenceTasks(buddy, presence.getType());
if (!BuddyList.getInstance().checkConnection()) {
return;
}
if (isSelf) {
BuddyList.getInstance().getStatusMenu()
.loadSelfStatuses();
}
BuddyList.getInstance().getBuddyListTree().removeBuddy(buddy,
buddy.getGroup(), false);
Roster roster = ConnectorThread.getInstance().getRoster();
if (roster == null) {
return;
}
if (!isSelf
&& (roster.getEntry(userId) != null || roster.getEntry(userId + "/" + resource) != null)) {
if (presence.getType() == Presence.Type.AVAILABLE
|| Settings.getInstance().getBoolean(
"showOfflineBuddies")) {
BuddyList.getInstance().getBuddyListTree().addBuddy(
buddy);
}