/**
* Processes incoming presence packets (from group chats)
*/
public void processPacket(Packet packet) {
final Presence presence = (Presence) packet;
final String from = packet.getFrom();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
boolean redraw = false;
//right now we find out if we have already received a packet
// from them,
//and if not, we set up an information "account" in the system
MUCBuddyStatus buddy = window.getBuddyStatus(from);
window.removeBuddy(buddy.getUser());
// get the role and affiliation information
MUCUser user = (MUCUser) presence.getExtension("x",
"http://jabber.org/protocol/muc#user");
if (user != null) {
buddy.setMUCUser(user);
MUCUser.Item item = user.getItem();
if (item != null) {
if (item.getAffiliation() != null)
buddy.setAffiliation(item.getAffiliation());
if (item.getRole() != null)
buddy.setRole(item.getRole());
if(item.getAffiliation()!=null && item.getRole()!=null)
{
if(item.getAffiliation().equals("none") && item.getRole().equals("none"))
{
presence.setType(Presence.Type.UNAVAILABLE);
}
}
}
}
// update the relavent presence information
if (presence.getType() == Presence.Type.UNAVAILABLE ) {
ConversationPanel conv = buddy.getConversation();
if ((conv != null) && (conv instanceof ChatPanel))
((ChatPanel) conv).signedOff();
} else {
buddy.addResource("_no resource_", 5, presence.getMode(),
presence.getStatus());
}
//if we need to, reload the nicklist.
if (presence.getType() == Presence.Type.AVAILABLE) {
window.addBuddy(buddy.getUser());
String name = buddy.getName();
if (name == null)
return;
if (nickChange == null && !buddy.getIsInRoom()) {
String message = buddy.getName();
if( buddy.getJid() != null )
{
message += " (" + buddy.getJid() + ") ";
}
message += " has entered the room";
window.serverNoticeMessage(message);
PluginChain.fireEvent(new MUCEvent(buddy.getUser(),
MUCEvent.EVENT_PARTICIPANT_JOINED, "",
new Date()));
} else if (nickChange != null) {
nickChange.setIsInRoom(false);
window.serverNoticeMessage(nickChange.getName()
+ " is now known as " + buddy.getName());
window.removeBuddy(nickChange.getUser());
}
buddy.setIsInRoom(true);
nickChange = null;
} else if (presence.getType() == Presence.Type.UNAVAILABLE) {
buddy.setIsInRoom(false);
window.getBuddyStatuses().remove(buddy);
String leaveMessage = buddy.getName()
+ " has left the room";
PluginChain.fireEvent(new MUCEvent(buddy.getUser(),
MUCEvent.EVENT_PARTICIPANT_PARTED, "", new Date()));
if (presence.getStatus() != null
&& !presence.getStatus().equals("")) {
leaveMessage += ": " + presence.getStatus();
}
if (nickChange == null)
window.serverNoticeMessage(leaveMessage);
else