Search in sources :

Example 1 with InputDialog

use of org.jivesoftware.spark.component.InputDialog in project Spark by igniterealtime.

the class ContactList method sendMessages.

private void sendMessages(Collection<ContactItem> items) {
    StringBuilder buf = new StringBuilder();
    InputDialog dialog = new InputDialog();
    final String messageText = dialog.getInput(Res.getString("title.broadcast.message"), Res.getString("message.enter.broadcast.message"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), SparkManager.getMainWindow());
    if (ModelUtil.hasLength(messageText)) {
        final Map<String, Message> broadcastMessages = new HashMap<>();
        for (ContactItem item : items) {
            final Message message = new Message();
            message.setTo(item.getJID());
            final Map<String, Object> properties = new HashMap<>();
            properties.put("broadcast", true);
            message.addExtension(new JivePropertiesExtension(properties));
            message.setBody(messageText);
            if (!broadcastMessages.containsKey(item.getJID())) {
                buf.append(item.getDisplayName()).append("\n");
                broadcastMessages.put(item.getJID(), message);
            }
        }
        for (Message message : broadcastMessages.values()) {
            try {
                SparkManager.getConnection().sendStanza(message);
            } catch (SmackException.NotConnectedException e) {
                Log.warning("Unable to send broadcast to " + message.getTo(), e);
            }
        }
        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
        JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.broadcasted.to", buf.toString()), Res.getString("title.notification"), JOptionPane.INFORMATION_MESSAGE);
    }
}
Also used : InputDialog(org.jivesoftware.spark.component.InputDialog) Message(org.jivesoftware.smack.packet.Message) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Aggregations

Message (org.jivesoftware.smack.packet.Message)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 InputDialog (org.jivesoftware.spark.component.InputDialog)1