Search in sources :

Example 11 with GroupChatRoom

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

the class GroupChatRoomListener method chatRoomLeft.

@Override
public void chatRoomLeft(ChatRoom room) {
    if (!(room instanceof GroupChatRoom)) {
        return;
    }
    GroupChatRoom groupChatRoom = (GroupChatRoom) room;
    groupChatRoom.getConferenceRoomInfo().getAgentInfoPanel().setVisible(false);
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom)

Example 12 with GroupChatRoom

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

the class GroupChatRoomListener method userHasLeft.

@Override
public void userHasLeft(ChatRoom room, String userid) {
    if (!(room instanceof GroupChatRoom)) {
        return;
    }
    GroupChatRoom groupChatRoom = (GroupChatRoom) room;
    int index = groupChatRoom.getConferenceRoomInfo().getIndex(userid);
    if (index != -1) {
        groupChatRoom.getConferenceRoomInfo().removeUser(userid);
        groupChatRoom.getConferenceRoomInfo().getUserMap().remove(userid);
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom)

Example 13 with GroupChatRoom

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

the class GroupChatRoomListener method chatRoomClosed.

@Override
public void chatRoomClosed(ChatRoom room) {
    if (!(room instanceof GroupChatRoom)) {
        return;
    }
    GroupChatRoom groupChatRoom = (GroupChatRoom) room;
    MultiUserChat chat = groupChatRoom.getMultiUserChat();
    chat.removeParticipantListener(groupChatRoom.getConferenceRoomInfo().getListener());
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat)

Example 14 with GroupChatRoom

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

the class InvitationDialog method inviteUsersToRoom.

public void inviteUsersToRoom(final String serviceName, Collection<BookmarkedConference> rooms, String adHocRoomName, Collection<String> jids) {
    fillRoomsUI(rooms, adHocRoomName);
    JFrame parent = SparkManager.getChatManager().getChatContainer().getChatFrame();
    if (parent == null || !parent.isVisible()) {
        parent = SparkManager.getMainWindow();
    }
    // Add jids to user list
    if (jids != null) {
        for (Object jid : jids) {
            invitedUsers.addElement(jid);
        }
    }
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.invite.to.conference"), Res.getString("message.invite.users.to.conference"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("invite"), Res.getString("cancel") };
    pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    final JOptionPane p = new JOptionPane();
    dlg = p.createDialog(parent, Res.getString("title.conference.rooms"));
    dlg.setModal(false);
    dlg.pack();
    dlg.setSize(500, 450);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(parent);
    PropertyChangeListener changeListener = e -> {
        String value = (String) pane.getValue();
        if (Res.getString("cancel").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        } else if (Res.getString("invite").equals(value)) {
            final String roomTitle = getSelectedRoomName();
            final BookmarkedConference selectedBookmarkedConf = getSelectedBookmarkedConference();
            int size = invitedUserList.getModel().getSize();
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            if (size == 0) {
                JOptionPane.showMessageDialog(dlg, Res.getString("message.specify.users.to.join.conference"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                return;
            }
            if (!ModelUtil.hasLength(roomTitle)) {
                JOptionPane.showMessageDialog(dlg, Res.getString("message.no.room.to.join.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                return;
            }
            String roomName = "";
            // Add all rooms the user is in to list.
            ChatManager chatManager = SparkManager.getChatManager();
            for (ChatRoom chatRoom : chatManager.getChatContainer().getChatRooms()) {
                if (chatRoom instanceof GroupChatRoom) {
                    GroupChatRoom groupRoom = (GroupChatRoom) chatRoom;
                    if (groupRoom.getRoomname().equals(roomTitle)) {
                        roomName = groupRoom.getMultiUserChat().getRoom();
                        break;
                    }
                }
            }
            String message = messageField.getText();
            final String messageText = message != null ? message : Res.getString("message.please.join.in.conference");
            if (invitedUsers.getSize() > 0) {
                invitedUserList.setSelectionInterval(0, invitedUsers.getSize() - 1);
            }
            GroupChatRoom chatRoom;
            try {
                chatRoom = SparkManager.getChatManager().getGroupChat(roomName);
            } catch (ChatNotFoundException e1) {
                dlg.setVisible(false);
                final List<String> jidList = new ArrayList<>();
                Object[] jids1 = invitedUserList.getSelectedValues();
                final int no = jids1 != null ? jids1.length : 0;
                for (int i = 0; i < no; i++) {
                    try {
                        jidList.add((String) jids1[i]);
                    } catch (NullPointerException ee) {
                        Log.error(ee);
                    }
                }
                SwingWorker worker = new SwingWorker() {

                    public Object construct() {
                        try {
                            Thread.sleep(15);
                        } catch (InterruptedException e2) {
                            Log.error(e2);
                        }
                        return "ok";
                    }

                    public void finished() {
                        try {
                            if (selectedBookmarkedConf == null) {
                                ConferenceUtils.createPrivateConference(serviceName, messageText, roomTitle, jidList);
                            } else {
                                ConferenceUtils.joinConferenceOnSeperateThread(selectedBookmarkedConf.getName(), selectedBookmarkedConf.getJid(), selectedBookmarkedConf.getPassword(), messageText, jidList);
                            }
                        } catch (SmackException ex) {
                            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                            JOptionPane.showMessageDialog(pane, "An error occurred.", Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                        }
                    }
                };
                worker.start();
                pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                return;
            }
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
            Object[] values = invitedUserList.getSelectedValues();
            final int no = values != null ? values.length : 0;
            for (int i = 0; i < no; i++) {
                String jid = (String) values[i];
                try {
                    chatRoom.getMultiUserChat().invite(jid, message != null ? message : Res.getString("message.please.join.in.conference"));
                } catch (SmackException.NotConnectedException e1) {
                    Log.warning("Unable to send stanza to " + jid, e1);
                }
                String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
                chatRoom.getTranscriptWindow().insertNotificationMessage("Invited " + nickname, ChatManager.NOTIFICATION_COLOR);
            }
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) UIManager(javax.swing.UIManager) Insets(java.awt.Insets) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) Log(org.jivesoftware.spark.util.log.Log) Action(javax.swing.Action) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) BorderLayout(java.awt.BorderLayout) JComponent(javax.swing.JComponent) ChatManager(org.jivesoftware.spark.ChatManager) ModelUtil(org.jivesoftware.spark.util.ModelUtil) JButton(javax.swing.JButton) SparkRes(org.jivesoftware.resource.SparkRes) JPopupMenu(javax.swing.JPopupMenu) Collection(java.util.Collection) JList(javax.swing.JList) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JOptionPane(javax.swing.JOptionPane) GridBagConstraints(java.awt.GridBagConstraints) TitlePanel(org.jivesoftware.spark.component.TitlePanel) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ActionEvent(java.awt.event.ActionEvent) XmppStringUtils(org.jxmpp.util.XmppStringUtils) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) PropertyChangeListener(java.beans.PropertyChangeListener) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) RosterPickList(org.jivesoftware.spark.ui.RosterPickList) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) PropertyChangeListener(java.beans.PropertyChangeListener) SmackException(org.jivesoftware.smack.SmackException) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) RosterPickList(org.jivesoftware.spark.ui.RosterPickList) ChatManager(org.jivesoftware.spark.ChatManager)

Example 15 with GroupChatRoom

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

the class JoinRoomSwingWorker method construct.

@Override
public Object construct() {
    try {
        groupChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
        // Create a UI component, if one was not yet created. It is important that this happens before the MUC is
        // joined server-side, as the UI component needs to be able to display data that is sent by the server upon
        // joining the room.
        ChatRoom room;
        try {
            final String roomName = XmppStringUtils.parseBareJid(groupChat.getRoom());
            room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
        } catch (ChatRoomNotFoundException e) {
            room = UIComponentRegistry.createGroupChatRoom(groupChat);
            ((GroupChatRoom) room).setPassword(password);
            ((GroupChatRoom) room).setTabTitle(tabTitle);
        }
        // Use the default nickname, if none has been provided.
        if (!ModelUtil.hasLength(nickname)) {
            nickname = SettingsManager.getRelodLocalPreferences().getNickname().trim();
        }
        // Join the MUC server-sided, if we're not already in.
        if (!groupChat.isJoined()) {
            if (password == null && ConferenceUtils.isPasswordRequired(roomJID)) {
                JLabel label = new JLabel(Res.getString("message.enter.room.password"));
                JPasswordField passwordField = new JPasswordField();
                passwordField.addAncestorListener(new RequestFocusListener());
                JOptionPane.showConfirmDialog(null, new Object[] { label, passwordField }, Res.getString("title.password.required"), JOptionPane.OK_CANCEL_OPTION);
                password = new String(passwordField.getPassword());
                if (!ModelUtil.hasLength(password)) {
                    return null;
                }
            }
            if (!ConferenceUtils.confirmToRevealVisibility()) {
                return null;
            }
            if (ModelUtil.hasLength(password)) {
                groupChat.join(nickname, password);
            } else {
                groupChat.join(nickname);
            }
        }
        return room;
    } catch (XMPPException | SmackException ex) {
        Log.error("An exception occurred while trying to join room '" + roomJID + "'.", ex);
        XMPPError error = null;
        if (ex instanceof XMPPException.XMPPErrorException) {
            error = ((XMPPException.XMPPErrorException) ex).getXMPPError();
            if (XMPPError.Condition.conflict.equals(error.getCondition())) {
                final Object userInput = JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("message.nickname.in.use"), Res.getString("title.change.nickname"), JOptionPane.WARNING_MESSAGE, null, // null selection values implies text field.
                null, nickname);
                if (userInput != null) {
                    Log.debug("Retry joining room '" + roomJID + "', using nickname: " + userInput);
                    this.nickname = (String) userInput;
                    return construct();
                }
            }
        }
        final String errorText = ConferenceUtils.getReason(error);
        errors.add(errorText);
        return null;
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) XMPPError(org.jivesoftware.smack.packet.XMPPError) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) RequestFocusListener(org.jivesoftware.spark.ui.RequestFocusListener) XMPPException(org.jivesoftware.smack.XMPPException)

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