Search in sources :

Example 11 with ChatRoomNotFoundException

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

ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)11 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)8 ChatManager (org.jivesoftware.spark.ChatManager)4 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)4 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)4 ChatContainer (org.jivesoftware.spark.ui.ChatContainer)3 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 Message (org.jivesoftware.smack.packet.Message)2 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)2 ContactItem (org.jivesoftware.spark.ui.ContactItem)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)1 VCard (org.jivesoftware.smackx.vcardtemp.packet.VCard)1