Search in sources :

Example 1 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.

the class BroadcastPlugin method userToUserBroadcast.

/**
 * Handles Broadcasts made from a user to another user
 *
 * @param message
 *            the message
 * @param type
 *            the message type
 * @param from
 *            the sender
 */
private void userToUserBroadcast(Message message, Type type, String from) {
    String jid = XmppStringUtils.parseBareJid(from);
    String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(jid);
    } catch (ChatRoomNotFoundException e) {
        chatRoom = new ChatRoomImpl(jid, nickname, nickname);
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    Message m = new Message();
    m.setBody(message.getBody());
    m.setTo(message.getTo());
    String broadcasttype = type == Message.Type.normal ? Res.getString("broadcast") : Res.getString("message.alert.notify");
    // m.setFrom(name +" "+broadcasttype);
    m.setFrom(nickname + " - " + broadcasttype);
    chatRoom.getTranscriptWindow().insertMessage(m.getFrom(), message, ChatManager.FROM_COLOR);
    chatRoom.addToTranscript(m, true);
    chatRoom.increaseUnreadMessageCount();
    broadcastRooms.add(chatRoom);
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (pref.getShowToasterPopup()) {
        SparkToaster toaster = new SparkToaster();
        toaster.setDisplayTime(30000);
        toaster.setBorder(BorderFactory.createBevelBorder(0));
        toaster.setTitle(nickname + " - " + broadcasttype);
        toaster.showToaster(message.getBody());
    }
    SparkManager.getChatManager().fireGlobalMessageReceievedListeners(chatRoom, message);
    DelayInformation inf = message.getExtension("delay", "urn:xmpp:delay");
    if (inf == null) {
        SoundPreference soundPreference = (SoundPreference) SparkManager.getPreferenceManager().getPreference(new SoundPreference().getNamespace());
        SoundPreferences preferences = soundPreference.getPreferences();
        if (preferences.isPlayIncomingSound()) {
            File incomingFile = new File(preferences.getIncomingSound());
            SparkManager.getSoundManager().playClip(incomingFile);
        }
    }
    chatRoom.addMessageListener(new MessageListener() {

        boolean waiting = true;

        public void messageReceived(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        public void messageSent(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        private void removeAsBroadcast(ChatRoom room) {
            if (waiting) {
                broadcastRooms.remove(room);
                // Notify decorators
                SparkManager.getChatManager().notifySparkTabHandlers(room);
                waiting = false;
            }
        }
    });
}
Also used : SoundPreference(org.jivesoftware.sparkimpl.preference.sounds.SoundPreference) Message(org.jivesoftware.smack.packet.Message) SoundPreferences(org.jivesoftware.sparkimpl.preference.sounds.SoundPreferences) MessageListener(org.jivesoftware.spark.ui.MessageListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ChatManager(org.jivesoftware.spark.ChatManager) File(java.io.File)

Example 2 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.

the class BuzzPlugin method initialize.

public void initialize() {
    ProviderManager.addExtensionProvider(ELEMENTNAME, NAMESPACE, new BuzzPacket.Provider());
    ProviderManager.addExtensionProvider(ELEMENTNAME_OLD, NAMESPACE_OLD, new BuzzPacket.Provider());
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        if (stanza instanceof Message) {
            final Message message = (Message) stanza;
            boolean buzz = message.getExtension(ELEMENTNAME_OLD, NAMESPACE_OLD) != null || message.getExtension(ELEMENTNAME, NAMESPACE) != null;
            if (buzz) {
                SwingUtilities.invokeLater(() -> shakeWindow(message));
            }
        }
    }, new StanzaTypeFilter(Message.class));
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListener() {

        public void chatRoomOpened(final ChatRoom room) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    addBuzzFeatureToChatRoom(room);
                }
            };
            TaskEngine.getInstance().schedule(task, 100);
        }

        public void chatRoomLeft(ChatRoom room) {
        }

        public void chatRoomClosed(ChatRoom room) {
        }

        public void chatRoomActivated(ChatRoom room) {
        }

        public void userHasJoined(ChatRoom room, String userid) {
        }

        public void userHasLeft(ChatRoom room, String userid) {
        }
    });
}
Also used : StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomListener(org.jivesoftware.spark.ui.ChatRoomListener)

Example 3 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.

the class RosterMemberPanel method callEnded.

/**
 * Called when the call is ended. This does basic container cleanup.
 */
public void callEnded() {
    if (!callWasTransferred) {
        historyPanel.callEnded();
        setStatus("Call Ended", redColor);
    }
    hangUpButton.setEnabled(false);
    hangUpButton.setOpaque(false);
    muteButton.setEnabled(false);
    muteButton.setOpaque(false);
    holdButton.setEnabled(false);
    holdButton.setOpaque(false);
    transferButton.setEnabled(false);
    setStatus("Call Ended", redColor);
    // Add notification to ChatRoom if one exists.
    final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
    if (chatRoom != null) {
        final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
        String time = formatter.format(new Date());
        chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callendedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
    }
    // If this is a standalone phone call with no associated ChatRoom
    // gray out title and show off-phone icon.
    final ChatRoom room = callManager.getAssociatedChatRoom(this);
    softPhone.addCallSession(room, SoftPhoneManager.CallRoomState.callWasEnded);
    // Notify
    SparkManager.getChatManager().notifySparkTabHandlers(room);
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.

the class RosterMemberPanel method changeState.

private void changeState(SoftPhoneManager.CallRoomState state) {
    final ChatRoom room = callManager.getAssociatedChatRoom(this);
    softPhone.addCallSession(room, state);
    SparkManager.getChatManager().notifySparkTabHandlers(room);
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

Example 5 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.

the class RosterMemberPanel method callStarted.

/**
 * Called when a new call is established.
 */
private void callStarted() {
    // Show History
    historyPanel.removeAll();
    historyPanel.addPreviousConversations(phoneNumber);
    hangUpButton.setEnabled(true);
    muteButton.setEnabled(true);
    holdButton.setEnabled(true);
    transferButton.setEnabled(true);
    setStatus(CONNECTED, false);
    // Add notification to ChatRoom if one exists.
    final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
    if (chatRoom != null) {
        final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
        String time = formatter.format(new Date());
        chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callstartedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ChatRoom (org.jivesoftware.spark.ui.ChatRoom)45 ChatManager (org.jivesoftware.spark.ChatManager)10 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)10 ActionEvent (java.awt.event.ActionEvent)8 Message (org.jivesoftware.smack.packet.Message)8 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)8 ContactItem (org.jivesoftware.spark.ui.ContactItem)7 Presence (org.jivesoftware.smack.packet.Presence)6 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)6 ActionListener (java.awt.event.ActionListener)5 MouseEvent (java.awt.event.MouseEvent)5 Date (java.util.Date)5 JButton (javax.swing.JButton)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 SmackException (org.jivesoftware.smack.SmackException)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JPopupMenu (javax.swing.JPopupMenu)4 SparkManager (org.jivesoftware.spark.SparkManager)4