Search in sources :

Example 21 with ChatRoom

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

the class Workspace method insertMessage.

private void insertMessage(final String bareJID, final Message message) throws ChatRoomNotFoundException {
    ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
    chatRoom.insertMessage(message);
    int chatLength = chatRoom.getTranscriptWindow().getDocument().getLength();
    chatRoom.getTranscriptWindow().setCaretPosition(chatLength);
    chatRoom.getChatInputEditor().requestFocusInWindow();
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

Example 22 with ChatRoom

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

the class Workspace method handleOfflineMessage.

/**
 * Creates a new room if necessary and inserts an offline message.
 *
 * @param message The Offline message.
 */
private void handleOfflineMessage(Message message) throws SmackException.NotConnectedException {
    if (!ModelUtil.hasLength(message.getBody())) {
        return;
    }
    String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    // Create the room if it does not exist.
    ChatRoom room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    if (!SparkManager.getChatManager().getChatContainer().getChatFrame().isVisible()) {
        SparkManager.getChatManager().getChatContainer().getChatFrame().setVisible(true);
    }
    // Insert offline message
    room.getTranscriptWindow().insertMessage(nickname, message, ChatManager.FROM_COLOR);
    room.addToTranscript(message, true);
    // Send display and notified message back.
    SparkManager.getMessageEventManager().sendDeliveredNotification(message.getFrom(), message.getStanzaId());
    SparkManager.getMessageEventManager().sendDisplayedNotification(message.getFrom(), message.getStanzaId());
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 23 with ChatRoom

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

the class SparkTransferManager method addSendFileButton.

private void addSendFileButton() {
    final ChatManager chatManager = SparkManager.getChatManager();
    chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {

        public void chatRoomOpened(final ChatRoom room) {
            if (!(room instanceof ChatRoomImpl)) {
                return;
            }
            // Otherwise,
            new ChatRoomTransferDecorator(room);
        }

        public void chatRoomClosed(ChatRoom room) {
        }
    });
}
Also used : ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 24 with ChatRoom

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

the class SparkTransferManager method handleTransferRequest.

private void handleTransferRequest(FileTransferRequest request, ContactList contactList) {
    // Check if a listener handled this request
    if (fireTransferListeners(request)) {
        return;
    }
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    String fileName = request.getFileName();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    ChatRoom chatRoom;
    if (contactItem != null) {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
    } else {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
    }
    TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
    transcriptWindow.insertCustomText(Res.getString("message.file.transfer.chat.window"), true, false, Color.BLACK);
    final ReceiveFileTransfer receivingMessageUI = new ReceiveFileTransfer();
    receivingMessageUI.acceptFileTransfer(request);
    chatRoom.addClosingListener(() -> receivingMessageUI.cancelTransfer());
    transcriptWindow.addComponent(receivingMessageUI);
    chatRoom.increaseUnreadMessageCount();
    chatRoom.scrollToBottom();
    String fileTransMsg = contactItem.getDisplayName() + " " + Res.getString("message.file.transfer.short.message") + " " + fileName;
    SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, fileTransMsg, Res.getString("message.file.transfer.notification"));
}
Also used : ReceiveFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveFileTransfer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 25 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom 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

ChatRoom (org.jivesoftware.spark.ui.ChatRoom)45 ChatManager (org.jivesoftware.spark.ChatManager)10 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)10 ActionEvent (java.awt.event.ActionEvent)8 Message (org.jivesoftware.smack.packet.Message)8 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)8 ContactItem (org.jivesoftware.spark.ui.ContactItem)7 Presence (org.jivesoftware.smack.packet.Presence)6 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)6 ActionListener (java.awt.event.ActionListener)5 MouseEvent (java.awt.event.MouseEvent)5 Date (java.util.Date)5 JButton (javax.swing.JButton)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 SmackException (org.jivesoftware.smack.SmackException)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JPopupMenu (javax.swing.JPopupMenu)4 SparkManager (org.jivesoftware.spark.SparkManager)4