if (status != null) status = status.replaceAll("&", "&");
if (connection == null || !connection.isConnected()) return;
if (collaborationDisabled) return;
setStatus(mode);
Presence presence = new Presence(type);
if (status == null) {
if (mode == Presence.Mode.available) {
status = InstantMessagingConstants.PRESENCE_MODE_AVAILABLE;
} else if (mode == Presence.Mode.away) {
status = InstantMessagingConstants.PRESENCE_MODE_AWAY;
} else if (mode == Presence.Mode.chat) {
status = InstantMessagingConstants.PRESENCE_MODE_CHAT;
} else if (mode == Presence.Mode.dnd) {
status = InstantMessagingConstants.PRESENCE_MODE_DND;
} else if (mode == Presence.Mode.xa) {
status = InstantMessagingConstants.PRESENCE_MODE_XAWAY;
}
presence.setStatus(status);
} else {
presence.setStatus(status);
}
setStatusMsg(presence.getStatus());
//setting prio when type == unavailable causes error on IM server
if (presence.getType() == Presence.Type.available) presence.setPriority(priority);
if (mode != null) presence.setMode(mode);
try {
connection.sendPacket(presence);
} catch (RuntimeException ex) {
Tracing.logWarn("Error while trying to send Instant Messaging packet for user: " + username + " .Errormessage: ", ex,
InstantMessagingClient.class);