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;
}
}
Aggregations