Search in sources :

Example 16 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat 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)

Example 17 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat 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 18 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.

the class InviteSwingWorker method construct.

@Override
public Object construct() {
    final Set<String> invitedJIDs = new HashSet<>();
    final MultiUserChat groupChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
    // Send invitations
    for (final String jid : invitees) {
        try {
            groupChat.invite(jid, invitation);
            invitedJIDs.add(jid);
        } catch (SmackException.NotConnectedException e) {
            Log.warning("Unable to invite " + jid + " to " + roomJID, e);
        }
    }
    return invitedJIDs;
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) SmackException(org.jivesoftware.smack.SmackException) HashSet(java.util.HashSet)

Example 19 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.

the class AgentConversations method checkPopup.

private void checkPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        // Check if monitor
        try {
            AgentConversation item = (AgentConversation) list.getSelectedValue();
            boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
            if (isMonitor) {
                JPopupMenu menu = new JPopupMenu();
                final String sessionID = item.getSessionID();
                Action joinAction = new AbstractAction() {

                    private static final long serialVersionUID = 8239167390330425891L;

                    public void actionPerformed(ActionEvent actionEvent) {
                        // Get Conference
                        try {
                            final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
                            Collection col = multiUserChatManager.getServiceNames();
                            if (col.size() == 0) {
                                return;
                            }
                            String serviceName = (String) col.iterator().next();
                            String roomName = sessionID + "@" + serviceName;
                            LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final String nickname = pref.getNickname();
                            MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
                            ConferenceUtils.enterRoom(muc, roomName, nickname, null);
                            if (muc.isJoined()) {
                                // Try and remove myself as an owner if I am one.
                                Collection owners = null;
                                try {
                                    owners = muc.getOwners();
                                } catch (XMPPException | SmackException e1) {
                                    return;
                                }
                                Iterator iter = owners.iterator();
                                List<String> list = new ArrayList<String>();
                                while (iter.hasNext()) {
                                    Affiliate affilitate = (Affiliate) iter.next();
                                    String jid = affilitate.getJid();
                                    if (!jid.equals(SparkManager.getSessionManager().getBareAddress())) {
                                        list.add(jid);
                                    }
                                }
                                if (list.size() > 0) {
                                    Form form = muc.getConfigurationForm().createAnswerForm();
                                    form.setAnswer("muc#roomconfig_roomowners", list);
                                    // new DataFormDialog(groupChat, form);
                                    muc.sendConfigurationForm(form);
                                }
                            }
                        } catch (Exception e1) {
                            Log.error(e1);
                        }
                    }
                };
                joinAction.putValue(Action.NAME, FpRes.getString("menuitem.join.chat"));
                menu.add(joinAction);
                Action monitorAction = new AbstractAction() {

                    private static final long serialVersionUID = -2072254190661466657L;

                    public void actionPerformed(ActionEvent actionEvent) {
                        // Make user an owner.
                        try {
                            FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
                            final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
                            Collection<String> col = multiUserChatManager.getServiceNames();
                            if (col.size() == 0) {
                                return;
                            }
                            String serviceName = (String) col.iterator().next();
                            String roomName = sessionID + "@" + serviceName;
                            LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final String nickname = pref.getNickname();
                            MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
                            ConferenceUtils.enterRoom(muc, roomName, nickname, null);
                        } catch (XMPPException | SmackException e1) {
                            Log.error(e1);
                        }
                    }
                };
                monitorAction.putValue(Action.NAME, FpRes.getString("menuitem.monitor.chat"));
                menu.add(monitorAction);
                menu.show(list, e.getX(), e.getY());
            }
        } catch (XMPPException | SmackException e1) {
            Log.error(e1);
            return;
        }
    }
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) Form(org.jivesoftware.smackx.xdata.Form) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) JPopupMenu(javax.swing.JPopupMenu) Affiliate(org.jivesoftware.smackx.muc.Affiliate) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) Iterator(java.util.Iterator) Collection(java.util.Collection) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException) AbstractAction(javax.swing.AbstractAction)

Example 20 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat in project Spark by igniterealtime.

the class CurrentActivity method checkPopup.

private void checkPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        // Check if monitor
        try {
            boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
            if (isMonitor) {
                JPopupMenu menu = new JPopupMenu();
                int location = list.locationToIndex(e.getPoint());
                list.setSelectedIndex(location);
                ConversationItem item = (ConversationItem) list.getSelectedValue();
                final String sessionID = item.getSessionID();
                Action joinAction = new AbstractAction() {

                    private static final long serialVersionUID = -3198414924157880065L;

                    public void actionPerformed(ActionEvent actionEvent) {
                        // Get Conference
                        try {
                            final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
                            Collection col = multiUserChatManager.getServiceNames();
                            if (col.size() == 0) {
                                return;
                            }
                            String serviceName = (String) col.iterator().next();
                            String roomName = sessionID + "@" + serviceName;
                            final LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final String nickname = pref.getNickname();
                            MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
                            ConferenceUtils.enterRoom(muc, roomName, nickname, null);
                            if (muc.isJoined()) {
                                // Try and remove myself as an owner if I am one.
                                Collection owners = null;
                                try {
                                    owners = muc.getOwners();
                                } catch (XMPPException | SmackException e1) {
                                    return;
                                }
                                Iterator iter = owners.iterator();
                                List<String> list = new ArrayList<String>();
                                while (iter.hasNext()) {
                                    Affiliate affilitate = (Affiliate) iter.next();
                                    String jid = affilitate.getJid();
                                    if (!jid.equals(SparkManager.getSessionManager().getBareAddress())) {
                                        list.add(jid);
                                    }
                                }
                                if (list.size() > 0) {
                                    Form form = muc.getConfigurationForm().createAnswerForm();
                                    form.setAnswer("muc#roomconfig_roomowners", list);
                                    // new DataFormDialog(groupChat, form);
                                    muc.sendConfigurationForm(form);
                                }
                            }
                        } catch (Exception e1) {
                            Log.error(e1);
                        }
                    }
                };
                joinAction.putValue(Action.NAME, FpRes.getString("menuitem.join.chat"));
                menu.add(joinAction);
                Action monitorAction = new AbstractAction() {

                    private static final long serialVersionUID = 7292337790553806820L;

                    public void actionPerformed(ActionEvent actionEvent) {
                        // Make user an owner.
                        try {
                            FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
                            MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
                            Collection<String> col = manager.getServiceNames();
                            if (col.size() == 0) {
                                return;
                            }
                            String serviceName = (String) col.iterator().next();
                            String roomName = sessionID + "@" + serviceName;
                            LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final String nickname = pref.getNickname();
                            MultiUserChat muc = manager.getMultiUserChat(roomName);
                            ConferenceUtils.enterRoom(muc, roomName, nickname, null);
                        } catch (XMPPException | SmackException e1) {
                            Log.error(e1);
                        }
                    }
                };
                monitorAction.putValue(Action.NAME, FpRes.getString("menuitem.monitor.chat"));
                menu.add(monitorAction);
                menu.show(list, e.getX(), e.getY());
            }
        } catch (XMPPException | SmackException e1) {
            Log.error(e1);
            return;
        }
    }
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) Form(org.jivesoftware.smackx.xdata.Form) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) JPopupMenu(javax.swing.JPopupMenu) Affiliate(org.jivesoftware.smackx.muc.Affiliate) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) Iterator(java.util.Iterator) Collection(java.util.Collection) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException) AbstractAction(javax.swing.AbstractAction)

Aggregations

MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)26 SmackException (org.jivesoftware.smack.SmackException)15 XMPPException (org.jivesoftware.smack.XMPPException)15 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)6 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)5 Form (org.jivesoftware.smackx.xdata.Form)5 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)3 BareJid (org.jxmpp.jid.BareJid)3 EntityBareJid (org.jxmpp.jid.EntityBareJid)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 RemoteException (android.os.RemoteException)2 NetworkException (com.xabber.android.data.NetworkException)2 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)2 UserJid (com.xabber.android.data.entity.UserJid)2