notifySubjectChangeListeners(new SubjectChangeEvent(ChatRoom.this, message.getSubject(), message.getFrom().getResource(), delayedDelivery != null, date));
} else {
notifyMessageListeners(new MessageEvent(ChatRoom.this, message, true));
}
} else {
MucUser mucUser = message.getExtension(MucUser.class);
if (mucUser != null) {
Decline decline = mucUser.getDecline();
if (decline != null) {
notifyInvitationDeclineListeners(new InvitationDeclineEvent(ChatRoom.this, roomJid, decline.getFrom(), decline.getReason()));
}
}
}
}
}
}
};
presenceListener = new PresenceListener() {
@Override
public void handle(PresenceEvent e) {
Presence presence = e.getPresence();
// If the presence came from the room.
if (presence.getFrom() != null && presence.getFrom().asBareJid().equals(roomJid)) {
if (e.isIncoming()) {
MucUser mucUser = presence.getExtension(MucUser.class);
if (mucUser != null) {
String nick = presence.getFrom().getResource();
if (nick != null) {
boolean isSelfPresence = isSelfPresence(presence);
if (presence.isAvailable()) {
Occupant occupant = new Occupant(presence, isSelfPresence);
Occupant previousOccupant = occupantMap.put(nick, occupant);
// A new occupant entered the room.
if (previousOccupant == null) {
// Only notify about "joins", if it's not our own join and we are already in the room.
if (!isSelfPresence && entered) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.ENTERED, null, null, null));
}
} else {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.STATUS_CHANGED, null, null, null));
}
} else if (presence.getType() == Presence.Type.UNAVAILABLE) {
// Occupant has exited the room.
Occupant occupant = occupantMap.remove(nick);
if (occupant != null) {
if (mucUser.getItem() != null) {
Actor actor = mucUser.getItem().getActor();
String reason = mucUser.getItem().getReason();
if (!mucUser.getStatusCodes().isEmpty()) {
if (mucUser.getStatusCodes().contains(Status.kicked())) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.KICKED, actor, reason, null));
} else if (mucUser.getStatusCodes().contains(Status.banned())) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.BANNED, actor, reason, null));
} else if (mucUser.getStatusCodes().contains(Status.membershipRevoked())) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.MEMBERSHIP_REVOKED, actor, reason, null));
} else if (mucUser.getStatusCodes().contains(Status.nicknameChanged())) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.NICKNAME_CHANGED, actor, reason, null));
} else if (mucUser.getStatusCodes().contains(Status.systemShutdown())) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.SYSTEM_SHUTDOWN, actor, reason, null));
}
} else if (mucUser.getDestroy() != null) {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.ROOM_DESTROYED, actor, mucUser.getDestroy().getReason(), mucUser.getDestroy().getJid()));
} else {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.EXITED, null, null, null));
}
} else {
notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.EXITED, null, null, null));