Search in sources :

Example 1 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat in project camel by apache.

the class XmppConsumer method doStart.

@Override
protected void doStart() throws Exception {
    try {
        connection = endpoint.createConnection();
    } catch (SmackException e) {
        if (endpoint.isTestConnectionOnStartup()) {
            throw new RuntimeException("Could not connect to XMPP server.", e);
        } else {
            LOG.warn(e.getMessage());
            if (getExceptionHandler() != null) {
                getExceptionHandler().handleException(e.getMessage(), e);
            }
            scheduleDelayedStart();
            return;
        }
    }
    chatManager = ChatManager.getInstanceFor(connection);
    chatManager.addChatListener(this);
    OrFilter pubsubPacketFilter = new OrFilter();
    if (endpoint.isPubsub()) {
        //xep-0060: pubsub#notification_type can be 'headline' or 'normal'
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
        connection.addPacketListener(this, pubsubPacketFilter);
    }
    if (endpoint.getRoom() == null) {
        privateChat = chatManager.getThreadChat(endpoint.getChatId());
        if (privateChat != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
            }
            privateChat.addMessageListener(this);
        } else {
            privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Opening private chat to " + privateChat.getParticipant());
            }
        }
    } else {
        // add the presence packet listener to the connection so we only get packets that concerns us
        // we must add the listener before creating the muc
        final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
        connection.addPacketListener(this, packetFilter);
        muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
        muc.addMessageListener(this);
        DiscussionHistory history = new DiscussionHistory();
        // we do not want any historical messages
        history.setMaxChars(0);
        muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
        if (LOG.isInfoEnabled()) {
            LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
        }
    }
    this.startRobustConnectionMonitor();
    super.doStart();
}
Also used : MessageTypeFilter(org.jivesoftware.smack.filter.MessageTypeFilter) AndFilter(org.jivesoftware.smack.filter.AndFilter) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DiscussionHistory(org.jivesoftware.smackx.muc.DiscussionHistory) SmackException(org.jivesoftware.smack.SmackException) Presence(org.jivesoftware.smack.packet.Presence) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter)

Example 2 with MultiUserChat

use of org.jivesoftware.smackx.muc.MultiUserChat in project opennms by OpenNMS.

the class XMPPNotificationManager method sendGroupChat.

/**
 * send an xmpp message to a specified Chat Room.
 *
 * @param xmppChatRoom
 *            room to send message to.
 * @param xmppMessage
 *            text to be sent in the body of the message
 * @return true if message is sent, false otherwise
 */
public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {
    MultiUserChat groupChat;
    if (rooms.containsKey(xmppChatRoom)) {
        groupChat = rooms.get(xmppChatRoom);
    } else {
        LOG.debug("Adding room: {}", xmppChatRoom);
        groupChat = new MultiUserChat(xmpp, xmppChatRoom);
        rooms.put(xmppChatRoom, groupChat);
    }
    if (!groupChat.isJoined()) {
        LOG.debug("Joining room: {}", xmppChatRoom);
        try {
            groupChat.join(xmppUser);
        } catch (XMPPException | NoResponseException | NotConnectedException e) {
            LOG.error("XMPP Exception joining chat room ", e);
            return false;
        }
    }
    try {
        groupChat.sendMessage(xmppMessage);
        LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
    } catch (XMPPException | NotConnectedException e) {
        LOG.error("XMPP Exception sending message to Chat room", e);
        return false;
    }
    return true;
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 3 with MultiUserChat

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

the class GroupChatRoomListener method chatRoomOpened.

@Override
public void chatRoomOpened(ChatRoom room) {
    if (!(room instanceof GroupChatRoom)) {
        return;
    }
    GroupChatRoom groupChatRoom = (GroupChatRoom) room;
    MultiUserChat chat = groupChatRoom.getMultiUserChat();
    chat.addUserStatusListener(new UserStatusListener() {

        public void kicked(String actor, String reason) {
        }

        public void voiceGranted() {
        }

        public void voiceRevoked() {
        }

        public void banned(String actor, String reason) {
        }

        public void membershipGranted() {
        }

        public void membershipRevoked() {
        }

        public void moderatorGranted() {
        }

        public void moderatorRevoked() {
        }

        public void ownershipGranted() {
        }

        public void ownershipRevoked() {
        }

        public void adminGranted() {
        }

        public void adminRevoked() {
        }
    });
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) UserStatusListener(org.jivesoftware.smackx.muc.UserStatusListener)

Example 4 with MultiUserChat

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

the class ConferenceUtils method createPrivateConference.

/**
 * Creates a private conference.
 *
 * @param serviceName the service name to use for the private conference.
 * @param message     the message sent to each individual invitee.
 * @param roomName    the name of the room to create.
 * @param jids        a collection of the user JIDs to invite.
 * @throws SmackException thrown if an error occurs during room creation.
 */
public static void createPrivateConference(String serviceName, String message, String roomName, Collection<String> jids) throws SmackException {
    final String roomJID = XmppStringUtils.escapeLocalpart(roomName) + "@" + serviceName;
    final MultiUserChat multiUserChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(multiUserChat);
    try {
        // Attempt to create room.
        multiUserChat.create(pref.getNickname());
    } catch (XMPPException | SmackException e) {
        throw new SmackException(e);
    }
    try {
        // Since this is a private room, make the room not public and set user as owner of the room.
        Form submitForm = multiUserChat.getConfigurationForm().createAnswerForm();
        submitForm.setAnswer("muc#roomconfig_publicroom", false);
        submitForm.setAnswer("muc#roomconfig_roomname", roomName);
        final List<String> owners = new ArrayList<>();
        owners.add(SparkManager.getSessionManager().getBareAddress());
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        multiUserChat.sendConfigurationForm(submitForm);
    } catch (XMPPException | SmackException e1) {
        Log.error("Unable to send conference room chat configuration form.", e1);
    }
    ChatManager chatManager = SparkManager.getChatManager();
    // Check if room already is open
    try {
        chatManager.getChatContainer().getChatRoom(room.getRoomname());
    } catch (ChatRoomNotFoundException e) {
        chatManager.getChatContainer().addChatRoom(room);
        chatManager.getChatContainer().activateChatRoom(room);
    }
    for (String jid : jids) {
        multiUserChat.invite(jid, message);
        room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.waiting.for.user.to.join", jid), ChatManager.NOTIFICATION_COLOR);
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Form(org.jivesoftware.smackx.xdata.Form) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) SmackException(org.jivesoftware.smack.SmackException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException) ChatManager(org.jivesoftware.spark.ChatManager) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager)

Example 5 with MultiUserChat

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

the class ChatManager method createConferenceRoom.

/**
 * Creates a new public Conference Room.
 *
 * @param roomName    the name of the room.
 * @param serviceName the service name to use (ex.conference.jivesoftware.com)
 * @return the new ChatRoom created. If an error occured, null will be returned.
 */
public ChatRoom createConferenceRoom(String roomName, String serviceName) {
    final MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomName + "@" + serviceName);
    final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(chatRoom);
    try {
        LocalPreferences pref = SettingsManager.getLocalPreferences();
        chatRoom.create(pref.getNickname());
        // Send an empty room configuration form which indicates that we want
        // an instant room
        chatRoom.sendConfigurationForm(new Form(DataForm.Type.submit));
    } catch (XMPPException | SmackException e1) {
        Log.error("Unable to send conference room chat configuration form.", e1);
        return null;
    }
    getChatContainer().addChatRoom(room);
    return room;
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

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