Search in sources :

Example 76 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class AgentConversations method checkPopup.

private void checkPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        // Check if monitor
        try {
            AgentConversation item = 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());
                            List<DomainBareJid> col = multiUserChatManager.getMucServiceDomains();
                            if (col.size() == 0) {
                                return;
                            }
                            DomainBareJid serviceName = col.iterator().next();
                            EntityBareJid roomName = JidCreate.entityBareFrom(sessionID + "@" + serviceName);
                            LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final Resourcepart 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<Affiliate> owners;
                                try {
                                    owners = muc.getOwners();
                                } catch (XMPPException | SmackException e1) {
                                    return;
                                }
                                Iterator<Affiliate> iter = owners.iterator();
                                List<Jid> list = new ArrayList<>();
                                while (iter.hasNext()) {
                                    Affiliate affilitate = iter.next();
                                    Jid jid = affilitate.getJid();
                                    if (!jid.equals(SparkManager.getSessionManager().getUserBareAddress())) {
                                        list.add(jid);
                                    }
                                }
                                if (list.size() > 0) {
                                    FillableForm form = muc.getConfigurationForm().getFillableForm();
                                    List<String> listStrings = JidUtil.toStringList(list);
                                    form.setAnswer("muc#roomconfig_roomowners", listStrings);
                                    // 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());
                            List<DomainBareJid> col = multiUserChatManager.getMucServiceDomains();
                            if (col.size() == 0) {
                                return;
                            }
                            DomainBareJid serviceName = col.iterator().next();
                            EntityBareJid roomName = JidCreate.entityBareFrom(sessionID + "@" + serviceName);
                            LocalPreferences pref = SettingsManager.getLocalPreferences();
                            final Resourcepart nickname = pref.getNickname();
                            MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
                            ConferenceUtils.enterRoom(muc, roomName, nickname, null);
                        } catch (XMPPException | SmackException | InterruptedException | XmppStringprepException 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 | InterruptedException e1) {
            Log.error(e1);
        }
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Affiliate(org.jivesoftware.smackx.muc.Affiliate) Resourcepart(org.jxmpp.jid.parts.Resourcepart) AbstractAction(javax.swing.AbstractAction) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) SmackException(org.jivesoftware.smack.SmackException) JPopupMenu(javax.swing.JPopupMenu) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3