Search in sources :

Example 1 with ChatRoomNotFoundException

use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.

the class BroadcastPlugin method userToUserBroadcast.

/**
 * Handles Broadcasts made from a user to another user
 *
 * @param message
 *            the message
 * @param type
 *            the message type
 * @param from
 *            the sender
 */
private void userToUserBroadcast(Message message, Type type, String from) {
    String jid = XmppStringUtils.parseBareJid(from);
    String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(jid);
    } catch (ChatRoomNotFoundException e) {
        chatRoom = new ChatRoomImpl(jid, nickname, nickname);
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    Message m = new Message();
    m.setBody(message.getBody());
    m.setTo(message.getTo());
    String broadcasttype = type == Message.Type.normal ? Res.getString("broadcast") : Res.getString("message.alert.notify");
    // m.setFrom(name +" "+broadcasttype);
    m.setFrom(nickname + " - " + broadcasttype);
    chatRoom.getTranscriptWindow().insertMessage(m.getFrom(), message, ChatManager.FROM_COLOR);
    chatRoom.addToTranscript(m, true);
    chatRoom.increaseUnreadMessageCount();
    broadcastRooms.add(chatRoom);
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (pref.getShowToasterPopup()) {
        SparkToaster toaster = new SparkToaster();
        toaster.setDisplayTime(30000);
        toaster.setBorder(BorderFactory.createBevelBorder(0));
        toaster.setTitle(nickname + " - " + broadcasttype);
        toaster.showToaster(message.getBody());
    }
    SparkManager.getChatManager().fireGlobalMessageReceievedListeners(chatRoom, message);
    DelayInformation inf = message.getExtension("delay", "urn:xmpp:delay");
    if (inf == null) {
        SoundPreference soundPreference = (SoundPreference) SparkManager.getPreferenceManager().getPreference(new SoundPreference().getNamespace());
        SoundPreferences preferences = soundPreference.getPreferences();
        if (preferences.isPlayIncomingSound()) {
            File incomingFile = new File(preferences.getIncomingSound());
            SparkManager.getSoundManager().playClip(incomingFile);
        }
    }
    chatRoom.addMessageListener(new MessageListener() {

        boolean waiting = true;

        public void messageReceived(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        public void messageSent(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        private void removeAsBroadcast(ChatRoom room) {
            if (waiting) {
                broadcastRooms.remove(room);
                // Notify decorators
                SparkManager.getChatManager().notifySparkTabHandlers(room);
                waiting = false;
            }
        }
    });
}
Also used : SoundPreference(org.jivesoftware.sparkimpl.preference.sounds.SoundPreference) Message(org.jivesoftware.smack.packet.Message) SoundPreferences(org.jivesoftware.sparkimpl.preference.sounds.SoundPreferences) MessageListener(org.jivesoftware.spark.ui.MessageListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ChatManager(org.jivesoftware.spark.ChatManager) File(java.io.File)

Example 2 with ChatRoomNotFoundException

use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.

the class InviteSwingWorker method finished.

@Override
public void finished() {
    final String roomName = XmppStringUtils.parseBareJid(roomJID);
    try {
        final ChatRoom room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
        final TranscriptWindow transcriptWindow = room.getTranscriptWindow();
        for (final String jid : (Set<String>) getValue()) {
            final String notification = Res.getString("message.waiting.for.user.to.join", jid);
            transcriptWindow.insertNotificationMessage(notification, ChatManager.NOTIFICATION_COLOR);
        }
    } catch (ChatRoomNotFoundException e) {
        Log.error("Unable to identify chat room tab by name: " + roomName);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException)

Example 3 with ChatRoomNotFoundException

use of org.jivesoftware.spark.ui.ChatRoomNotFoundException 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 4 with ChatRoomNotFoundException

use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.

the class OnlineAgents method activateChat.

/**
 * Activate a chat room with the selected user.
 */
private void activateChat(final String userJID, final String nickname) {
    if (!ModelUtil.hasLength(userJID)) {
        return;
    }
    SwingWorker worker = new SwingWorker() {

        final ChatManager chatManager = SparkManager.getChatManager();

        ChatRoom chatRoom;

        public Object construct() {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                Log.error("Error in activate chat.", e);
            }
            ChatContainer chatRooms = chatManager.getChatContainer();
            try {
                chatRoom = chatRooms.getChatRoom(userJID);
            } catch (ChatRoomNotFoundException e) {
                Log.warning("Room not found for jid: " + userJID, e);
            }
            return chatRoom;
        }

        public void finished() {
            if (chatRoom == null) {
                chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
                chatManager.getChatContainer().addChatRoom(chatRoom);
            }
            chatManager.getChatContainer().activateChatRoom(chatRoom);
        }
    };
    worker.start();
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 5 with ChatRoomNotFoundException

use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.

the class GroupChatParticipantList method startChat.

protected void startChat(ChatRoom groupChat, String groupJID) {
    String userNickname = XmppStringUtils.parseResource(groupJID);
    String roomTitle = userNickname + " - " + XmppStringUtils.parseLocalpart(groupChat.getRoomname());
    String nicknameOfUser = XmppStringUtils.parseResource(groupJID);
    String nickname = groupChat.getNickname();
    if (nicknameOfUser.equals(nickname)) {
        return;
    }
    ChatRoom chatRoom;
    try {
        chatRoom = chatManager.getChatContainer().getChatRoom(groupJID);
    } catch (ChatRoomNotFoundException e) {
        Log.debug("Could not find chat room - " + groupJID);
        // Create new room
        chatRoom = new ChatRoomImpl(groupJID, nicknameOfUser, roomTitle);
        chatManager.getChatContainer().addChatRoom(chatRoom);
    }
    chatManager.getChatContainer().activateChatRoom(chatRoom);
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Aggregations

ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)11 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)8 ChatManager (org.jivesoftware.spark.ChatManager)4 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)4 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)4 ChatContainer (org.jivesoftware.spark.ui.ChatContainer)3 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 Message (org.jivesoftware.smack.packet.Message)2 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)2 ContactItem (org.jivesoftware.spark.ui.ContactItem)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)1 VCard (org.jivesoftware.smackx.vcardtemp.packet.VCard)1