Search in sources :

Example 1 with ChatRoomImpl

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

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

the class ChatContainer method handleRoomPresence.

/**
 * Handles the presence of a one to one chat room.
 *
 * @param p the presence to handle.
 */
private void handleRoomPresence(final Presence p) {
    final String roomname = XmppStringUtils.parseBareJid(p.getFrom());
    ChatRoom chatRoom;
    try {
        chatRoom = getChatRoom(roomname);
    } catch (ChatRoomNotFoundException e1) {
        Log.debug("Could not locate chat room " + roomname);
        return;
    }
    final String userid = XmppStringUtils.parseResource(p.getFrom());
    if (p.getType() == Presence.Type.unavailable) {
        fireUserHasLeft(chatRoom, userid);
    } else if (p.getType() == Presence.Type.available) {
        fireUserHasJoined(chatRoom, userid);
    }
    // Change tab icon
    if (chatRoom instanceof ChatRoomImpl) {
        // Notify state change.
        int tabLoc = indexOfComponent(chatRoom);
        if (tabLoc != -1) {
            SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
        }
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 3 with ChatRoomImpl

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

the class ChatContainer method addChatRoom.

/**
 * Adds a new ChatRoom to Spark.
 *
 * @param room the ChatRoom to add.
 */
public synchronized void addChatRoom(final ChatRoom room) {
    createFrameIfNeeded();
    room.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
    AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(room.getRoomname()));
    // Next, create a packet listener. We use an anonymous inner class for brevity.
    StanzaListener myListener = stanza -> SwingUtilities.invokeLater(() -> handleRoomPresence((Presence) stanza));
    room.registeredToFrame(chatFrame);
    SparkManager.getConnection().addAsyncStanzaListener(myListener, presenceFilter);
    // Add to PresenceMap
    presenceMap.put(room.getRoomname(), myListener);
    String tooltip;
    if (room instanceof ChatRoomImpl) {
        tooltip = ((ChatRoomImpl) room).getParticipantJID();
        String nickname = SparkManager.getUserManager().getUserNicknameFromJID(((ChatRoomImpl) room).getParticipantJID());
        tooltip = "<html><body><b>Contact:&nbsp;</b>" + nickname + "<br><b>JID:&nbsp;</b>" + tooltip;
    } else {
        tooltip = room.getRoomname();
    }
    // Create ChatRoom UI and dock
    SparkTab tab = addTab(room.getTabTitle(), room.getTabIcon(), room, tooltip);
    tab.addMouseListener(new MouseAdapter() {

        public void mouseReleased(MouseEvent e) {
            checkTabPopup(e);
        }

        public void mousePressed(MouseEvent e) {
            checkTabPopup(e);
        }
    });
    room.addMessageListener(this);
    // Remove brand panel
    final String title = getTabAt(0).getActualText();
    if (title.equals(WELCOME_TITLE)) {
        chatFrame.setTitle(room.getRoomTitle());
    }
    final TimerTask visibleTask = new SwingTimerTask() {

        public void doRun() {
            checkVisibility(room);
        }
    };
    TaskEngine.getInstance().schedule(visibleTask, 100);
    // Add to ChatRoomList
    chatRoomList.add(room);
    // Notify users that the chat room has been opened.
    fireChatRoomOpened(room);
    // Focus Chat
    focusChat();
    // Add Room listeners to override issue with input maps and keybinding on the mac.
    if (Spark.isMac()) {
        room.getChatInputEditor().addKeyListener(this);
    }
}
Also used : java.util(java.util) SparkTabbedPaneListener(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPaneListener) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) MainWindow(org.jivesoftware.MainWindow) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) ChangeListener(javax.swing.event.ChangeListener) GroupChatRoomListener(org.jivesoftware.spark.ui.conferences.GroupChatRoomListener) AndFilter(org.jivesoftware.smack.filter.AndFilter) TaskEngine(org.jivesoftware.spark.util.TaskEngine) ChangeEvent(javax.swing.event.ChangeEvent) FromMatchesFilter(org.jivesoftware.smack.filter.FromMatchesFilter) Presence(org.jivesoftware.smack.packet.Presence) ChatManager(org.jivesoftware.spark.ChatManager) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SparkRes(org.jivesoftware.resource.SparkRes) SwingWorker(org.jivesoftware.spark.util.SwingWorker) SparkTabbedPane(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) XmppStringUtils(org.jxmpp.util.XmppStringUtils) Spark(org.jivesoftware.Spark) java.awt(java.awt) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) List(java.util.List) SparkManager(org.jivesoftware.spark.SparkManager) java.awt.event(java.awt.event) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) Pattern(java.util.regex.Pattern) StanzaListener(org.jivesoftware.smack.StanzaListener) javax.swing(javax.swing) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Presence(org.jivesoftware.smack.packet.Presence) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 4 with ChatRoomImpl

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

the class ChatManager method composingNotification.

public void composingNotification(final String from) {
    SwingUtilities.invokeLater(() -> {
        final ContactList contactList = SparkManager.getWorkspace().getContactList();
        ChatRoom chatRoom;
        try {
            chatRoom = getChatContainer().getChatRoom(XmppStringUtils.parseBareJid(from));
            if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
                typingNotificationList.add(chatRoom);
                // Notify Decorators
                notifySparkTabHandlers(chatRoom);
                ((ChatRoomImpl) chatRoom).notifyChatStateChange(ChatState.composing);
            }
        } catch (ChatRoomNotFoundException e) {
        // Do nothing
        }
        contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
    });
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 5 with ChatRoomImpl

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

the class ConversationHistoryPlugin method addUserToHistory.

/**
 * Adds the last user to the history tags.
 *
 * @param room the ChatRoom where the conversation took place.
 */
private void addUserToHistory(ChatRoom room) {
    if (room instanceof ChatRoomImpl) {
        ChatRoomImpl roomImpl = (ChatRoomImpl) room;
        String jid = roomImpl.getParticipantJID();
        jid = XmppStringUtils.parseBareJid(jid);
        historyList.remove(jid);
        historyList.add(0, jid);
    }
}
Also used : ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Aggregations

ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)25 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)9 ChatManager (org.jivesoftware.spark.ChatManager)8 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 File (java.io.File)4 StanzaListener (org.jivesoftware.smack.StanzaListener)4 Message (org.jivesoftware.smack.packet.Message)4 Presence (org.jivesoftware.smack.packet.Presence)4 ChatRoomButton (org.jivesoftware.spark.ui.ChatRoomButton)4 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 SmackException (org.jivesoftware.smack.SmackException)3 Stanza (org.jivesoftware.smack.packet.Stanza)3 SparkManager (org.jivesoftware.spark.SparkManager)3 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)3 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)3 java.awt.event (java.awt.event)2 TimerTask (java.util.TimerTask)2