Search in sources :

Example 11 with JivePropertiesExtension

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;
}
Also used : JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 12 with JivePropertiesExtension

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);
        }
    });
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) URISyntaxException(java.net.URISyntaxException) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) IOException(java.io.IOException)

Example 13 with JivePropertiesExtension

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;
}
Also used : JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 14 with JivePropertiesExtension

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);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 15 with JivePropertiesExtension

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();
}
Also used : Message(org.jivesoftware.smack.packet.Message) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Aggregations

JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)22 Message (org.jivesoftware.smack.packet.Message)13 HashMap (java.util.HashMap)7 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 Date (java.util.Date)2 SmackException (org.jivesoftware.smack.SmackException)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Stanza (org.jivesoftware.smack.packet.Stanza)2 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)2 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 CardLayout (java.awt.CardLayout)1 Color (java.awt.Color)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 BufferedWriter (java.io.BufferedWriter)1