use of org.jivesoftware.smack.packet.Message.Type in project Spark by igniterealtime.
the class BroadcastPlugin method showAlert.
/**
* Show Server Alert.
*
* @param message the message to show.
* @param type
*/
private void showAlert(Message message) {
Type type = message.getType();
// Do not show alert if the message is an error.
if (message.getError() != null) {
return;
}
final String body = message.getBody();
String subject = message.getSubject();
StringBuilder buf = new StringBuilder();
if (subject != null) {
buf.append(Res.getString("subject")).append(": ").append(subject);
buf.append("\n\n");
}
buf.append(body);
String from = message.getFrom() != null ? message.getFrom() : "";
final TranscriptWindow window = new TranscriptWindow();
window.insertNotificationMessage(buf.toString(), ChatManager.TO_COLOR);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(window, BorderLayout.CENTER);
p.setBorder(BorderFactory.createLineBorder(Color.lightGray));
// Count the number of linebreaks <br> and \n
String s = message.getBody();
s = s.replace("<br/>", "\n");
s = s.replace("<br>", "\n");
int linebreaks = org.jivesoftware.spark.util.StringUtils.countNumberOfOccurences(s, '\n');
// Currently Serverbroadcasts dont contain Subjects, so this might be a MOTD message
boolean mightbeMOTD = message.getSubject() != null;
if (!from.contains("@")) {
// if theres no "@" it means the message came from the server
if (Default.getBoolean(Default.BROADCAST_IN_CHATWINDOW) || linebreaks > 20 || message.getBody().length() > 1000 || mightbeMOTD) {
// if we have more than 20 linebreaks or the message is longer
// than 1000characters we should broadcast
// in a normal chatwindow
broadcastInChat(message);
} else {
broadcastWithPanel(message);
}
} else if (message.getFrom() != null) {
userToUserBroadcast(message, type, from);
}
}
Aggregations