Search in sources :

Example 6 with ChatRoomNotFoundException

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

the class BroadcastPlugin method broadcastInChat.

/**
 * Displays the Serverbroadcast like all other messages
 * in its on chatcontainer with transcript history
 * @param message
 * @param from
 */
private void broadcastInChat(Message message) {
    String from = message.getFrom() != null ? message.getFrom() : "";
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(from);
    } catch (ChatRoomNotFoundException e) {
        String windowtitle = message.getSubject() != null ? message.getSubject() : Res.getString("administrator");
        chatRoom = new ChatRoomImpl("serveralert@" + from, Res.getString("broadcast"), windowtitle);
        chatRoom.getBottomPanel().setVisible(false);
        chatRoom.hideToolbar();
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(message.getBody(), ChatManager.NOTIFICATION_COLOR);
    broadcastRooms.add(chatRoom);
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 7 with ChatRoomNotFoundException

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

the class BuzzPlugin method shakeWindow.

private void shakeWindow(Message message) {
    String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
    ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    ChatRoom room;
    try {
        room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
    } catch (ChatRoomNotFoundException e) {
        // Create the room if it does not exist.
        room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    }
    ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
    if (chatFrame != null) {
        if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
            chatFrame.buzz();
            SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
        }
    }
    // Insert offline message
    room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
    room.scrollToBottom();
}
Also used : ChatFrame(org.jivesoftware.spark.ui.ChatFrame) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 8 with ChatRoomNotFoundException

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

the class RoarMessageListener method messageReceived.

@Override
public void messageReceived(ChatRoom room, Message message) {
    try {
        ChatRoom activeroom = SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
        int framestate = SparkManager.getChatManager().getChatContainer().getChatFrame().getState();
        if (framestate == JFrame.NORMAL && activeroom.equals(room) && room.isShowing() && (isOldGroupChat(room) || isMessageFromRoom(room, message))) {
        // Do Nothing
        } else {
            decideForRoomAndMessage(room, message);
        }
    } catch (ChatRoomNotFoundException e) {
    // i dont care
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException)

Example 9 with ChatRoomNotFoundException

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

the class Workspace method handleIncomingPacket.

private void handleIncomingPacket(Stanza stanza) throws SmackException.NotConnectedException {
    // We only handle message packets here.
    if (stanza instanceof Message) {
        final Message message = (Message) stanza;
        boolean isGroupChat = message.getType() == Message.Type.groupchat;
        // Check if Conference invite. If so, do not handle here.
        if (message.getExtension("x", "jabber:x:conference") != null) {
            return;
        }
        final String body = message.getBody();
        final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
        final boolean broadcast = extension != null && extension.getProperty("broadcast") != null;
        // Handle offline message.
        DelayInformation offlineInformation = message.getExtension("delay", "urn:xmpp:delay");
        if (offlineInformation != null && (Message.Type.chat == message.getType() || Message.Type.normal == message.getType())) {
            handleOfflineMessage(message);
        }
        if (body == null || isGroupChat || broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline || message.getType() == Message.Type.error) {
            return;
        }
        // Create new chat room for Agent Invite.
        final String from = stanza.getFrom();
        final String host = SparkManager.getSessionManager().getServerAddress();
        // Don't allow workgroup notifications to come through here.
        final String bareJID = XmppStringUtils.parseBareJid(from);
        if (host.equalsIgnoreCase(from) || from == null) {
            return;
        }
        ChatRoom room = null;
        try {
            room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
        } catch (ChatRoomNotFoundException e) {
        // Ignore
        }
        // Check for non-existent rooms.
        if (room == null) {
            createOneToOneRoom(bareJID, message);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 10 with ChatRoomNotFoundException

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

the class Workspace method createOneToOneRoom.

/**
 * Creates a new room based on an anonymous user.
 *
 * @param bareJID the bareJID of the anonymous user.
 * @param message the message from the anonymous user.
 */
private void createOneToOneRoom(String bareJID, Message message) {
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    } else {
        // Attempt to load VCard from users who we are not subscribed to.
        VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
        if (vCard != null && vCard.getError() == null) {
            String firstName = vCard.getFirstName();
            String lastName = vCard.getLastName();
            String userNickname = vCard.getNickName();
            if (ModelUtil.hasLength(userNickname)) {
                nickname = userNickname;
            } else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                nickname = firstName + " " + lastName;
            } else if (ModelUtil.hasLength(firstName)) {
                nickname = firstName;
            }
        }
    }
    SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    try {
        insertMessage(bareJID, message);
    } catch (ChatRoomNotFoundException e) {
        Log.error("Could not find chat room.", e);
    }
}
Also used : ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ContactItem(org.jivesoftware.spark.ui.ContactItem) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

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