Search in sources :

Example 1 with ChatContainer

use of org.jivesoftware.spark.ui.ChatContainer 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 ChatContainer

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

the class CallManager method getSparkTab.

/**
 * Returns the <code>SparkTab</code> that acts as a container to this PhonePanel.
 *
 * @param phonePanel the <code>PhonePanel</code>
 * @return the SparkTab.
 */
public SparkTab getSparkTab(PhonePanel phonePanel) {
    final ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
    int tabCount = chatContainer.getTabCount();
    for (int i = 0; i < tabCount; i++) {
        SparkTab sparkTab = chatContainer.getTabAt(i);
        Component containerComponent = chatContainer.getComponentInTab(sparkTab);
        if (containerComponent.equals(phonePanel)) {
            return sparkTab;
        }
        if (containerComponent instanceof ChatRoom) {
            ChatRoom chatRoom = (ChatRoom) containerComponent;
            Component rightComponent = chatRoom.getSplitPane().getRightComponent();
            if (phonePanel.equals(rightComponent)) {
                return sparkTab;
            }
        }
    }
    return null;
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

Example 3 with ChatContainer

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

the class UserSearchResults method openChatRoom.

private void openChatRoom(int row) {
    String jid = (String) resultsTable.getValueAt(row, 0);
    String nickname = XmppStringUtils.parseLocalpart(jid);
    TableColumn column;
    try {
        column = resultsTable.getColumn("nick");
        int col = column.getModelIndex();
        nickname = (String) resultsTable.getValueAt(row, col);
        if (!ModelUtil.hasLength(nickname)) {
            nickname = XmppStringUtils.parseLocalpart(jid);
        }
    } catch (Exception e1) {
    // Ignore e1
    }
    ChatManager chatManager = SparkManager.getChatManager();
    ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
    ChatContainer chatRooms = chatManager.getChatContainer();
    chatRooms.activateChatRoom(chatRoom);
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TableColumn(javax.swing.table.TableColumn) ChatManager(org.jivesoftware.spark.ChatManager)

Example 4 with ChatContainer

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

the class OnlineAgents method activateChat.

/**
 * Activate a chat room with the selected user.
 */
private void activateChat(final String userJID, final String nickname) {
    if (!ModelUtil.hasLength(userJID)) {
        return;
    }
    SwingWorker worker = new SwingWorker() {

        final ChatManager chatManager = SparkManager.getChatManager();

        ChatRoom chatRoom;

        public Object construct() {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                Log.error("Error in activate chat.", e);
            }
            ChatContainer chatRooms = chatManager.getChatContainer();
            try {
                chatRoom = chatRooms.getChatRoom(userJID);
            } catch (ChatRoomNotFoundException e) {
                Log.warning("Room not found for jid: " + userJID, e);
            }
            return chatRoom;
        }

        public void finished() {
            if (chatRoom == null) {
                chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
                chatManager.getChatContainer().addChatRoom(chatRoom);
            }
            chatManager.getChatContainer().activateChatRoom(chatRoom);
        }
    };
    worker.start();
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 5 with ChatContainer

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

the class BroadcastPlugin method broadcastInChat.

/**
 * Displays the Serverbroadcast like all other messages
 * in its on chatcontainer with transcript history
 * @param message
 * @param from
 */
private void broadcastInChat(Message message) {
    String from = message.getFrom() != null ? message.getFrom() : "";
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(from);
    } catch (ChatRoomNotFoundException e) {
        String windowtitle = message.getSubject() != null ? message.getSubject() : Res.getString("administrator");
        chatRoom = new ChatRoomImpl("serveralert@" + from, Res.getString("broadcast"), windowtitle);
        chatRoom.getBottomPanel().setVisible(false);
        chatRoom.hideToolbar();
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(message.getBody(), ChatManager.NOTIFICATION_COLOR);
    broadcastRooms.add(chatRoom);
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Aggregations

ChatContainer (org.jivesoftware.spark.ui.ChatContainer)6 ChatManager (org.jivesoftware.spark.ChatManager)5 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)4 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)3 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)3 File (java.io.File)1 TableColumn (javax.swing.table.TableColumn)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Message (org.jivesoftware.smack.packet.Message)1 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)1 ChatNotFoundException (org.jivesoftware.spark.ChatNotFoundException)1 SparkTab (org.jivesoftware.spark.component.tabbedPane.SparkTab)1 MessageListener (org.jivesoftware.spark.ui.MessageListener)1 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)1 SwingWorker (org.jivesoftware.spark.util.SwingWorker)1 SoundPreference (org.jivesoftware.sparkimpl.preference.sounds.SoundPreference)1 SoundPreferences (org.jivesoftware.sparkimpl.preference.sounds.SoundPreferences)1