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();
}
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());
}
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) {
}
});
}
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"));
}
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);
}
Aggregations