}
}
@Override
public void onPresenceReceived(final PresenceReceivedEvent event) {
final Presence presence = event.getPresence();
final RosterItem item = getItemByJID(presence.getFrom());
if (item != null) {
final String resource = presence.getFrom().getResource();
boolean hasChanged = false;
final boolean wasAvailable = item.getAvailableResources().contains(resource);
if (presence.getType() == Presence.Type.unavailable) {
if (wasAvailable) {
hasChanged = true;
item.setAvailable(false, resource);
}
} else {
if (!wasAvailable) {
hasChanged = true;
item.setAvailable(true, resource);
}
}
if (!presence.getShow().equals(item.getShow())) {
hasChanged = true;
item.setShow(presence.getShow());
}
if (item.getStatus() == null && presence.getStatus() != null || item.getStatus() != null && !item.getStatus().equals(presence.getStatus())) {
hasChanged = true;
item.setStatus(presence.getStatus());
}
if (hasChanged) {
final RosterItemChangedEvent changeEvent = new RosterItemChangedEvent(ChangeType.modified, item);
eventBus.fireEventFromSource(changeEvent, this);