use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Smack by igniterealtime.
the class JivePropertiesManager method getProperty.
/**
* Convenience method to get a property from a packet. Will return null if the stanza(/packet) contains
* not property with the given name.
*
* @param packet
* @param name
* @return the property or <tt>null</tt> if none found.
*/
public static Object getProperty(Stanza packet, String name) {
Object res = null;
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null) {
res = jpe.getProperty(name);
}
return res;
}
use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Spark by igniterealtime.
the class BroadcastPlugin method processPacket.
public void processPacket(final Stanza stanza) {
SwingUtilities.invokeLater(() -> {
try {
final Message message = (Message) stanza;
// Do not handle errors or offline messages
final DelayInformation offlineInformation = message.getExtension("delay", "urn:xmpp:delay");
if (offlineInformation != null || message.getError() != null) {
return;
}
final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
final boolean broadcast = extension != null && extension.getProperty("broadcast") != null;
if ((broadcast || message.getType() == Type.normal || message.getType() == Type.headline) && message.getBody() != null) {
showAlert((Message) stanza);
} else {
String host = SparkManager.getSessionManager().getServerAddress();
String from = stanza.getFrom() != null ? stanza.getFrom() : "";
if (host.equalsIgnoreCase(from) || !ModelUtil.hasLength(from)) {
showAlert((Message) stanza);
}
}
} catch (Exception e) {
Log.error(e);
}
});
}
use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Spark by igniterealtime.
the class RoarPopupHelper method getNickname.
/**
* Returns the Nickname of the person sending the message
*
* @param room
* the ChatRoom the message was sent in
* @param message
* the actual message
* @return nickname
*/
public static String getNickname(ChatRoom room, Message message) {
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom());
if (room.getChatType() == Message.Type.groupchat) {
nickname = XmppStringUtils.parseResource(nickname);
}
final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
final boolean broadcast = extension != null && extension.getProperty("broadcast") != null;
if ((broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline) && message.getBody() != null) {
nickname = Res.getString("broadcast") + " - " + nickname;
}
return nickname;
}
use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Spark by igniterealtime.
the class Workspace method handleIncomingPacket.
private void handleIncomingPacket(Stanza stanza) throws SmackException.NotConnectedException {
// We only handle message packets here.
if (stanza instanceof Message) {
final Message message = (Message) stanza;
boolean isGroupChat = message.getType() == Message.Type.groupchat;
// Check if Conference invite. If so, do not handle here.
if (message.getExtension("x", "jabber:x:conference") != null) {
return;
}
final String body = message.getBody();
final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
final boolean broadcast = extension != null && extension.getProperty("broadcast") != null;
// Handle offline message.
DelayInformation offlineInformation = message.getExtension("delay", "urn:xmpp:delay");
if (offlineInformation != null && (Message.Type.chat == message.getType() || Message.Type.normal == message.getType())) {
handleOfflineMessage(message);
}
if (body == null || isGroupChat || broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline || message.getType() == Message.Type.error) {
return;
}
// Create new chat room for Agent Invite.
final String from = stanza.getFrom();
final String host = SparkManager.getSessionManager().getServerAddress();
// Don't allow workgroup notifications to come through here.
final String bareJID = XmppStringUtils.parseBareJid(from);
if (host.equalsIgnoreCase(from) || from == null) {
return;
}
ChatRoom room = null;
try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} catch (ChatRoomNotFoundException e) {
// Ignore
}
// Check for non-existent rooms.
if (room == null) {
createOneToOneRoom(bareJID, message);
}
}
}
use of org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension in project Spark by igniterealtime.
the class ChatRoom method addToTranscript.
/**
* Add a <code>ChatResponse</chat> to the current discussion chat area.
*
* @param message the message to add to the transcript list
* @param updateDate true if you wish the date label to be updated with the
* date and time the message was received.
*/
public void addToTranscript(Message message, boolean updateDate) {
// Create message to persist.
final Message newMessage = new Message();
newMessage.setTo(message.getTo());
newMessage.setFrom(message.getFrom());
newMessage.setBody(message.getBody());
final Map<String, Object> properties = new HashMap<>();
properties.put("date", new Date());
newMessage.addExtension(new JivePropertiesExtension(properties));
transcript.add(newMessage);
// Add current date if this is the current agent
if (updateDate && transcriptWindow.getLastUpdated() != null) {
// Set new label date
notificationLabel.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_ABOUT_IMAGE));
notificationLabel.setText(Res.getString("message.last.message.received", SparkManager.DATE_SECOND_FORMATTER.format(transcriptWindow.getLastUpdated())));
}
scrollToBottom();
}
Aggregations