Search in sources :

Example 6 with GroupChatRoom

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

the class BannedUsers method setChatRoom.

/**
 * Binds a ChatRoom to listen to.
 *
 * @param cRoom the group chat room.
 */
public void setChatRoom(ChatRoom cRoom) {
    GroupChatRoom chatRoom = (GroupChatRoom) cRoom;
    chat = chatRoom.getMultiUserChat();
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom)

Example 7 with GroupChatRoom

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

the class ChatRoom method handleNickNameCompletion.

/**
 * Handles the Nickname Completion dialog, when Pressing CTRL + SPACE<br>
 * it searches for matches in the current GroupchatList and also in the
 * Roster
 *
 * @throws ChatRoomNotFoundException
 *             when for some reason the GroupChatRoom cannot be found, this
 *             should <u>not</u> happen, since we retrieve it from the
 *             ActiveWindowTab and thus <u>can be ignored</u>
 */
private void handleNickNameCompletion() throws ChatRoomNotFoundException {
    // Search for a name that starts with the same word as the last word in the chat input editor.
    final String text = getChatInputEditor().getText();
    if (text == null || text.isEmpty()) {
        return;
    }
    // -1 when space does not occur.
    final int lastSpaceCharacterIndex = text.lastIndexOf(' ');
    final String needle = text.substring(lastSpaceCharacterIndex + 1);
    final Set<String> matches = new TreeSet<>(String::compareToIgnoreCase);
    if (SparkManager.getChatManager().getChatContainer().getActiveChatRoom() instanceof GroupChatRoom) {
        final GroupChatRoom activeChatRoom = (GroupChatRoom) SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
        for (String participant : activeChatRoom.getParticipants()) {
            final String nickname = participant.substring(participant.lastIndexOf("/") + 1);
            if (nickname.toLowerCase().startsWith(needle.toLowerCase())) {
                matches.add(nickname);
            }
        }
    } else {
        for (RosterEntry re : Roster.getInstanceFor(SparkManager.getConnection()).getEntries()) {
            // Use the name if available, otherwise the localpart of the JID.
            final String username;
            if (re.getName() != null) {
                username = re.getName();
            } else {
                username = re.getUser().substring(0, re.getUser().indexOf('@'));
            }
            if (username.toLowerCase().startsWith(needle.toLowerCase())) {
                matches.add(username);
            }
        }
    }
    if (matches.size() == 1) {
        // If we only have 1 match, that match can be used immediately.
        getChatInputEditor().appendText(matches.iterator().next().substring(needle.length()));
    } else {
        // More than one match: create Popupmenu and let the user select one.
        final JPopupMenu popup = new JPopupMenu();
        for (final String match : matches) {
            final JMenuItem menuItem = new JMenuItem(match);
            popup.add(menuItem);
            menuItem.addActionListener(new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    getChatInputEditor().appendText(match.substring(needle.length()));
                    popup.setVisible(false);
                }
            });
        }
        popup.show(SparkManager.getChatManager().getChatContainer(), getChatInputEditor().getCaret().getMagicCaretPosition().x, SparkManager.getChatManager().getChatContainer().getHeight() - 20);
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 8 with GroupChatRoom

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

the class ConferenceRoomBrowser method createRoom.

/**
 * Create a new room based on room table selection.
 */
private void createRoom() {
    RoomCreationDialog mucRoomDialog = new RoomCreationDialog();
    final MultiUserChat groupChat = mucRoomDialog.createGroupChat(SparkManager.getMainWindow(), serviceName);
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (null != groupChat) {
        // Join Room
        try {
            GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(groupChat);
            groupChat.create(pref.getNickname());
            chatManager.getChatContainer().addChatRoom(room);
            chatManager.getChatContainer().activateChatRoom(room);
            // Send Form
            Form form = groupChat.getConfigurationForm().createAnswerForm();
            if (mucRoomDialog.isPasswordProtected()) {
                String password = mucRoomDialog.getPassword();
                room.setPassword(password);
                form.setAnswer("muc#roomconfig_passwordprotectedroom", true);
                form.setAnswer("muc#roomconfig_roomsecret", password);
            }
            form.setAnswer("muc#roomconfig_roomname", mucRoomDialog.getRoomName());
            form.setAnswer("muc#roomconfig_roomdesc", mucRoomDialog.getRoomTopic());
            if (mucRoomDialog.isPermanent()) {
                form.setAnswer("muc#roomconfig_persistentroom", true);
            }
            List<String> owners = new ArrayList<>();
            owners.add(SparkManager.getSessionManager().getBareAddress());
            form.setAnswer("muc#roomconfig_roomowners", owners);
            // new DataFormDialog(groupChat, form);
            groupChat.sendConfigurationForm(form);
            addRoomToTable(groupChat.getRoom(), XmppStringUtils.parseLocalpart(groupChat.getRoom()), 1);
        } catch (XMPPException | SmackException e1) {
            Log.error("Error creating new room.", e1);
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            JOptionPane.showMessageDialog(this, Res.getString("message.room.creation.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

Example 9 with GroupChatRoom

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

the class ConferenceUtils method isChatRoomClosable.

public static boolean isChatRoomClosable(Component c) {
    if (c instanceof GroupChatRoom) {
        GroupChatRoom groupChatRoom = (GroupChatRoom) c;
        String roomName = groupChatRoom.getChatRoom().getRoomname();
        if (unclosableChatRooms.contains(roomName)) {
            return false;
        }
    }
    return true;
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom)

Example 10 with GroupChatRoom

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

the class UserInvitationPane method startFastpathChat.

private void startFastpathChat(String fullRoomJID, String roomName) {
    // Add to Chat window
    ChatManager chatManager = SparkManager.getChatManager();
    GroupChatRoom chatRoom;
    try {
        chatRoom = chatManager.getGroupChat(fullRoomJID);
        if (!chatRoom.isActive()) {
            // Remove old room, add new room.
            chatManager.removeChat(chatRoom);
            MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
            chatRoom = new GroupChatRoom(chat);
        } else {
            // Already in the room, do not process invitation
            try {
                offer.reject();
            } catch (SmackException.NotConnectedException e) {
                Log.warning("Unable to reject offer " + offer, e);
            }
            return;
        }
    } catch (ChatNotFoundException e) {
        MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
        chatRoom = new GroupChatRoom(chat);
    }
    chatRoom.getSplitPane().setDividerSize(5);
    chatRoom.getSplitPane().getRightComponent().setVisible(true);
    chatRoom.getBottomPanel().setVisible(true);
    chatRoom.getScrollPaneForTranscriptWindow().setVisible(true);
    chatRoom.getEditorBar().setVisible(true);
    chatRoom.getChatInputEditor().setEnabled(true);
    chatRoom.getToolBar().setVisible(true);
    chatRoom.getVerticalSlipPane().setDividerLocation(0.8);
    chatRoom.getSplitPane().setDividerLocation(0.6);
    try {
        chatRoom.setTabTitle(roomName);
        chatRoom.getConferenceRoomInfo().setNicknameChangeAllowed(false);
        chatRoom.getToolBar().setVisible(true);
        chatRoom.getEditorBar().setVisible(true);
        chatRoom.getChatInputEditor().setEnabled(true);
        ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
        chatContainer.addChatRoom(chatRoom);
        FastpathPlugin.getLitWorkspace().addFastpathChatRoom(chatRoom, Workpane.RoomState.activeRoom);
        chatContainer.setChatRoomTitle(chatRoom, roomName);
        if (chatContainer.getActiveChatRoom() == chatRoom) {
            chatContainer.getChatFrame().setTitle(roomName);
        }
    } catch (Exception e) {
        Log.error(e);
    }
    ConferenceUtils.enterRoomOnSameThread(roomName, fullRoomJID, null);
    removeOwner(chatRoom.getMultiUserChat());
    FastpathPlugin.getLitWorkspace().checkForDecoration(chatRoom, offer.getSessionID());
    if (listener != null) {
        listener.yesOption();
        listener = null;
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException) SmackException(org.jivesoftware.smack.SmackException) ChatManager(org.jivesoftware.spark.ChatManager) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException)

Aggregations

GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)18 SmackException (org.jivesoftware.smack.SmackException)8 XMPPException (org.jivesoftware.smack.XMPPException)6 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)6 Form (org.jivesoftware.smackx.xdata.Form)4 ArrayList (java.util.ArrayList)3 ChatManager (org.jivesoftware.spark.ChatManager)3 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 ChatNotFoundException (org.jivesoftware.spark.ChatNotFoundException)2 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 BorderLayout (java.awt.BorderLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1