Search in sources :

Example 1 with Affiliate

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

the class InvitationPane method removeOwner.

/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    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;
        }
        if (owners == null) {
            return;
        }
        Iterator iter = owners.iterator();
        List list = new ArrayList();
        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) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                form.setAnswer("muc#roomconfig_roomowners", list);
                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            } catch (XMPPException | SmackException e) {
                Log.error(e);
            }
        }
    }
}
Also used : Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) XMPPException(org.jivesoftware.smack.XMPPException) Affiliate(org.jivesoftware.smackx.muc.Affiliate)

Example 2 with Affiliate

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

the class UserInvitationPane method removeOwner.

/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection<Affiliate> owners = null;
        try {
            owners = muc.getOwners();
        } catch (XMPPException | SmackException e1) {
            return;
        }
        if (owners == null) {
            return;
        }
        Iterator<Affiliate> iter = owners.iterator();
        List<String> list = new ArrayList<String>();
        while (iter.hasNext()) {
            Affiliate affilitate = iter.next();
            String jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                form.setAnswer("muc#roomconfig_roomowners", list);
                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            } catch (XMPPException | SmackException e) {
                Log.error(e);
            }
        }
    }
}
Also used : Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) XMPPException(org.jivesoftware.smack.XMPPException) Affiliate(org.jivesoftware.smackx.muc.Affiliate)

Example 3 with Affiliate

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

the class BannedUsers method loadAllBannedUsers.

/**
 * Loads all banned users in a ChatRoom.
 */
public void loadAllBannedUsers() {
    // Clear all elements from model
    listModel.clear();
    Iterator<Affiliate> bannedUsers = null;
    try {
        bannedUsers = chat.getOutcasts().iterator();
    } catch (XMPPException | SmackException e) {
        Log.error("Error loading all banned users", e);
    }
    while (bannedUsers != null && bannedUsers.hasNext()) {
        Affiliate bannedUser = bannedUsers.next();
        ImageIcon icon = SparkRes.getImageIcon(SparkRes.STAR_RED_IMAGE);
        icon.setDescription(bannedUser.getJid());
        listModel.addElement(icon);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) Affiliate(org.jivesoftware.smackx.muc.Affiliate)

Example 4 with Affiliate

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

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

SmackException (org.jivesoftware.smack.SmackException)5 XMPPException (org.jivesoftware.smack.XMPPException)5 Affiliate (org.jivesoftware.smackx.muc.Affiliate)5 ArrayList (java.util.ArrayList)4 Form (org.jivesoftware.smackx.xdata.Form)4 Collection (java.util.Collection)3 Iterator (java.util.Iterator)3 ActionEvent (java.awt.event.ActionEvent)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 JPopupMenu (javax.swing.JPopupMenu)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 List (java.util.List)1 ImageIcon (javax.swing.ImageIcon)1