Search in sources :

Example 1 with MultiUserChatManager

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

the class ConferenceServices method invitationReceived.

@Override
public void invitationReceived(final XMPPConnection conn, final MultiUserChat room, final String inviter, final String reason, final String password, final Message message) {
    SwingUtilities.invokeLater(() -> {
        Collection<RoomInvitationListener> listeners = new ArrayList<>(SparkManager.getChatManager().getInvitationListeners());
        for (RoomInvitationListener listener : listeners) {
            boolean handle = listener.handleInvitation(conn, room, inviter, reason, password, message);
            if (handle) {
                return;
            }
        }
        // room.
        try {
            SparkManager.getChatManager().getChatContainer().getChatRoom(room.getRoom());
            return;
        } catch (ChatRoomNotFoundException e) {
        // Ignore :)
        }
        final GroupChatInvitationUI invitationUI = new GroupChatInvitationUI(room.getRoom(), inviter, password, reason);
        String message1 = Res.getString("message.invite.to.groupchat", inviter);
        String title = Res.getString("title.group.chat");
        String bareJID = XmppStringUtils.parseBareJid(inviter);
        if (_localPreferences.isAutoAcceptMucInvite()) {
            ConferenceUtils.enterRoomOnSameThread(XmppStringUtils.parseLocalpart(room.getRoom()), room.getRoom(), password);
            MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
            GroupChatRoom chat = UIComponentRegistry.createGroupChatRoom(manager.getMultiUserChat(room.getRoom()));
            showToaster(message1, title, chat);
            return;
        // Nothing to do here, we want to join the
        // room, and stuff
        }
        try {
            ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
            // If the ChatRoom exists, add an invitationUI.
            chatRoom.getTranscriptWindow().addComponent(invitationUI);
            // Notify user of incoming invitation.
            chatRoom.increaseUnreadMessageCount();
            chatRoom.scrollToBottom();
            SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, message1, title);
        } catch (ChatRoomNotFoundException e) {
            // If it doesn't exists. Create a new Group
            // Chat Room
            // Create the Group Chat Room
            final MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
            final GroupChatRoom groupChatRoom = UIComponentRegistry.createGroupChatRoom(manager.getMultiUserChat(room.getRoom()));
            showToaster(message1, title, groupChatRoom);
            groupChatRoom.getSplitPane().setDividerSize(5);
            groupChatRoom.getVerticalSlipPane().setDividerLocation(0.6);
            groupChatRoom.getSplitPane().setDividerLocation(0.6);
            String roomName = XmppStringUtils.parseLocalpart(room.getRoom());
            groupChatRoom.setTabTitle(roomName);
            groupChatRoom.getToolBar().setVisible(true);
            SparkManager.getChatManager().getChatContainer().addChatRoom(groupChatRoom);
            groupChatRoom.getTranscriptWindow().addComponent(invitationUI);
            // Notify user of incoming invitation.
            groupChatRoom.increaseUnreadMessageCount();
            groupChatRoom.scrollToBottom();
            SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(groupChatRoom, true, message1, title);
        }
    // If no listeners handled the invitation,
    // default to generic invite.
    // new ConversationInvitation(conn, room,
    // inviter, reason, password, message);
    });
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ArrayList(java.util.ArrayList)

Example 2 with MultiUserChatManager

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

the class ChatManager method getDefaultConferenceService.

/**
 * Returns the default conference service. (ex. conference.jivesoftware.com)
 *
 * @return the default conference service to interact with MUC.
 */
public String getDefaultConferenceService() {
    if (conferenceService == null) {
        try {
            final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
            Collection<String> col = multiUserChatManager.getServiceNames();
            if (col.size() > 0) {
                conferenceService = col.iterator().next();
            }
        } catch (XMPPException | SmackException e) {
            Log.error(e);
        }
    }
    return conferenceService;
}
Also used : MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 3 with MultiUserChatManager

use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Smack by igniterealtime.

the class OmemoService method getMuc.

/**
 * Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined.
 *
 * @param connection xmpp connection
 * @param jid jid (presumably) of the MUC
 * @return MultiUserChat or null if not a MUC.
 */
private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) {
    EntityBareJid ebj = jid.asEntityBareJidIfPossible();
    if (ebj == null) {
        return null;
    }
    MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
    Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms();
    if (joinedRooms.contains(ebj)) {
        return mucm.getMultiUserChat(ebj);
    }
    return null;
}
Also used : MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 4 with MultiUserChatManager

use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Payara by payara.

the class XmppNotificationRunnable method run.

@Override
public void run() {
    while (queue.size() > 0) {
        try {
            XmppMessage xmppMessage = queue.getMessage();
            MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
            MultiUserChat multiUserChat = manager.getMultiUserChat(executionOptions.getRoomId() + "@" + executionOptions.getServiceName());
            if (multiUserChat != null) {
                if (!multiUserChat.isJoined()) {
                    multiUserChat.join(executionOptions.getUsername(), executionOptions.getPassword());
                }
                Message message = new Message();
                message.setSubject(xmppMessage.getSubject());
                message.setBody(xmppMessage.getMessage());
                multiUserChat.sendMessage(message);
            }
            logger.log(Level.FINE, "Message sent successfully");
        } catch (XMPPException | SmackException e) {
            logger.log(Level.SEVERE, "Error occurred while sending message to room", e);
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) Message(org.jivesoftware.smack.packet.Message) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 5 with MultiUserChatManager

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

Aggregations

MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)6 SmackException (org.jivesoftware.smack.SmackException)4 XMPPException (org.jivesoftware.smack.XMPPException)4 ArrayList (java.util.ArrayList)3 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)3 ActionEvent (java.awt.event.ActionEvent)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 JPopupMenu (javax.swing.JPopupMenu)2 Affiliate (org.jivesoftware.smackx.muc.Affiliate)2 Form (org.jivesoftware.smackx.xdata.Form)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 Message (org.jivesoftware.smack.packet.Message)1 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1