use of org.jivesoftware.spark.ChatNotFoundException 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;
}
}
use of org.jivesoftware.spark.ChatNotFoundException 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();
}
Aggregations