SPARK-1206: New chat window is not opened while receiving offline messages on login

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12042 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Konstantin Zolotarev
2011-03-01 10:07:47 +00:00
committed by konstantin.zolotarev
parent 69fe8cc70b
commit 1dc59309f8

View File

@ -1,138 +1,138 @@
/** /**
* $RCSfile: ,v $ * $RCSfile: ,v $
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2004-2010 Jive Software. All rights reserved. * Copyright (C) 2004-2010 Jive Software. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jivesoftware.spark; package org.jivesoftware.spark;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.TimerTask; import java.util.TimerTask;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jivesoftware.MainWindow; import org.jivesoftware.MainWindow;
import org.jivesoftware.MainWindowListener; import org.jivesoftware.MainWindowListener;
import org.jivesoftware.Spark; import org.jivesoftware.Spark;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow; import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
import org.jivesoftware.smackx.packet.DelayInformation; import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.packet.VCard; import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane; import org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane;
import org.jivesoftware.spark.filetransfer.SparkTransferManager; import org.jivesoftware.spark.filetransfer.SparkTransferManager;
import org.jivesoftware.spark.search.SearchManager; import org.jivesoftware.spark.search.SearchManager;
import org.jivesoftware.spark.ui.ChatContainer; import org.jivesoftware.spark.ui.ChatContainer;
import org.jivesoftware.spark.ui.ChatRoom; import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomNotFoundException; import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
import org.jivesoftware.spark.ui.CommandPanel; import org.jivesoftware.spark.ui.CommandPanel;
import org.jivesoftware.spark.ui.ContactItem; import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList; import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.ui.conferences.ConferenceServices; import org.jivesoftware.spark.ui.conferences.ConferenceServices;
import org.jivesoftware.spark.ui.status.StatusBar; import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.util.ModelUtil; import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.TaskEngine; import org.jivesoftware.spark.util.TaskEngine;
import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.alerts.BroadcastPlugin; import org.jivesoftware.sparkimpl.plugin.alerts.BroadcastPlugin;
import org.jivesoftware.sparkimpl.plugin.bookmarks.BookmarkPlugin; import org.jivesoftware.sparkimpl.plugin.bookmarks.BookmarkPlugin;
import org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin; import org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin;
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise; import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
import org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscriptPlugin; import org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscriptPlugin;
/** /**
* The inner Container for Spark. The Workspace is the container for all plugins into the Spark * The inner Container for Spark. The Workspace is the container for all plugins into the Spark
* install. Plugins would use this for the following: * install. Plugins would use this for the following:
* <p/> * <p/>
* <ul> * <ul>
* <li>Add own tab to the main tabbed pane. ex. * <li>Add own tab to the main tabbed pane. ex.
* <p/> * <p/>
* <p/> * <p/>
* Workspace workspace = SparkManager.getWorkspace(); * Workspace workspace = SparkManager.getWorkspace();
* JButton button = new JButton("HELLO SPARK USERS"); * JButton button = new JButton("HELLO SPARK USERS");
* workspace.getWorkspacePane().addTab("MyPlugin", button); * workspace.getWorkspacePane().addTab("MyPlugin", button);
* </p> * </p>
* <p/> * <p/>
* <li>Retrieve the ContactList. * <li>Retrieve the ContactList.
*/ */
public class Workspace extends JPanel implements PacketListener { public class Workspace extends JPanel implements PacketListener {
private static final long serialVersionUID = 7076407890063933765L; private static final long serialVersionUID = 7076407890063933765L;
private SparkTabbedPane workspacePane; private SparkTabbedPane workspacePane;
private StatusBar statusBox; private StatusBar statusBox;
private CommandPanel commandPanel; private CommandPanel commandPanel;
private ContactList contactList; private ContactList contactList;
private ConferenceServices conferences; private ConferenceServices conferences;
private GatewayPlugin gatewayPlugin; private GatewayPlugin gatewayPlugin;
private BookmarkPlugin bookmarkPlugin; private BookmarkPlugin bookmarkPlugin;
private ChatTranscriptPlugin transcriptPlugin; private ChatTranscriptPlugin transcriptPlugin;
private BroadcastPlugin broadcastPlugin; private BroadcastPlugin broadcastPlugin;
private static Workspace singleton; private static Workspace singleton;
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private JPanel cardPanel; private JPanel cardPanel;
private CardLayout cardLayout; private CardLayout cardLayout;
public static final String WORKSPACE_PANE = "WORKSPACE_PANE"; public static final String WORKSPACE_PANE = "WORKSPACE_PANE";
/** /**
* Returns the singleton instance of <CODE>Workspace</CODE>, * Returns the singleton instance of <CODE>Workspace</CODE>,
* creating it if necessary. * creating it if necessary.
* <p/> * <p/>
* *
* @return the singleton instance of <Code>Workspace</CODE> * @return the singleton instance of <Code>Workspace</CODE>
*/ */
public static Workspace getInstance() { public static Workspace getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating // Synchronize on LOCK to ensure that we don't end up creating
// two singletons. // two singletons.
synchronized (LOCK) { synchronized (LOCK) {
if (null == singleton) { if (null == singleton) {
Workspace controller = new Workspace(); Workspace controller = new Workspace();
singleton = controller; singleton = controller;
return controller; return controller;
} }
} }
return singleton; return singleton;
} }
/** /**
* Creates the instance of the SupportChatWorkspace. * Creates the instance of the SupportChatWorkspace.
*/ */
private Workspace() { private Workspace() {
final MainWindow mainWindow = SparkManager.getMainWindow(); final MainWindow mainWindow = SparkManager.getMainWindow();
// Add MainWindow listener // Add MainWindow listener
mainWindow.addMainWindowListener(new MainWindowListener() { mainWindow.addMainWindowListener(new MainWindowListener() {
public void shutdown() { public void shutdown() {
@ -158,325 +158,329 @@ public class Workspace extends JPanel implements PacketListener {
} }
}); });
// Initialize workspace pane, defaulting the tabs to the bottom. // Initialize workspace pane, defaulting the tabs to the bottom.
workspacePane = new SparkTabbedPane(JTabbedPane.BOTTOM); workspacePane = new SparkTabbedPane(JTabbedPane.BOTTOM);
// Add Panels. // Add Panels.
cardLayout = new CardLayout(); cardLayout = new CardLayout();
cardPanel = new JPanel(cardLayout); cardPanel = new JPanel(cardLayout);
cardPanel.setOpaque(false); cardPanel.setOpaque(false);
cardPanel.add(WORKSPACE_PANE, this); cardPanel.add(WORKSPACE_PANE, this);
statusBox = new StatusBar(); statusBox = new StatusBar();
commandPanel = new CommandPanel(); commandPanel = new CommandPanel();
// Build default workspace // Build default workspace
this.setLayout(new GridBagLayout()); this.setLayout(new GridBagLayout());
add(workspacePane, new GridBagConstraints(0, 9, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 4, 4, 4), 0, 0)); add(workspacePane, new GridBagConstraints(0, 9, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 4, 4, 4), 0, 0));
add(statusBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0)); add(statusBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0));
add(commandPanel, new GridBagConstraints(0, 5, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 0, 4), 0, 0)); add(commandPanel, new GridBagConstraints(0, 5, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 0, 4), 0, 0));
this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F12"), "showDebugger"); this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F12"), "showDebugger");
this.getActionMap().put("showDebugger", new AbstractAction("showDebugger") { this.getActionMap().put("showDebugger", new AbstractAction("showDebugger") {
private static final long serialVersionUID = 4066886679016416923L; private static final long serialVersionUID = 4066886679016416923L;
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
EnhancedDebuggerWindow window = EnhancedDebuggerWindow.getInstance(); EnhancedDebuggerWindow window = EnhancedDebuggerWindow.getInstance();
window.setVisible(true); window.setVisible(true);
} }
}); });
// Set background // Set background
setBackground(new Color(235, 239, 254)); setBackground(new Color(235, 239, 254));
} }
/** /**
* Builds the Workspace layout. * Builds the Workspace layout.
*/ */
public void buildLayout() { public void buildLayout() {
new Enterprise(); new Enterprise();
// Initialize Contact List // Initialize Contact List
contactList = new ContactList(); contactList = new ContactList();
conferences = new ConferenceServices(); conferences = new ConferenceServices();
// Init contact list. // Init contact list.
contactList.initialize(); contactList.initialize();
// Load VCard information for status box // Load VCard information for status box
statusBox.loadVCard(); statusBox.loadVCard();
// Initialise TransferManager // Initialise TransferManager
SparkTransferManager.getInstance(); SparkTransferManager.getInstance();
} }
/** /**
* Starts the Loading of all Spark Plugins. * Starts the Loading of all Spark Plugins.
*/ */
public void loadPlugins() { public void loadPlugins() {
// Add presence and message listeners // Add presence and message listeners
// we listen for these to force open a 1-1 peer chat window from other operators if // we listen for these to force open a 1-1 peer chat window from other operators if
// one isn't already open // one isn't already open
PacketFilter workspaceMessageFilter = new PacketTypeFilter(Message.class); PacketFilter workspaceMessageFilter = new PacketTypeFilter(Message.class);
// Add the packetListener to this instance // Add the packetListener to this instance
SparkManager.getSessionManager().getConnection().addPacketListener(this, workspaceMessageFilter); SparkManager.getSessionManager().getConnection().addPacketListener(this, workspaceMessageFilter);
// Make presence available to anonymous requests, if from anonymous user in the system. // Make presence available to anonymous requests, if from anonymous user in the system.
PacketListener workspacePresenceListener = new PacketListener() { PacketListener workspacePresenceListener = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
Presence presence = (Presence)packet; Presence presence = (Presence)packet;
if (presence.getProperty("anonymous") != null) { if (presence.getProperty("anonymous") != null) {
boolean isAvailable = statusBox.getPresence().getMode() == Presence.Mode.available; boolean isAvailable = statusBox.getPresence().getMode() == Presence.Mode.available;
Presence reply = new Presence(Presence.Type.available); Presence reply = new Presence(Presence.Type.available);
if (!isAvailable) { if (!isAvailable) {
reply.setType(Presence.Type.unavailable); reply.setType(Presence.Type.unavailable);
} }
reply.setTo(presence.getFrom()); reply.setTo(presence.getFrom());
SparkManager.getSessionManager().getConnection().sendPacket(reply); SparkManager.getSessionManager().getConnection().sendPacket(reply);
} }
} }
}; };
SparkManager.getSessionManager().getConnection().addPacketListener(workspacePresenceListener, new PacketTypeFilter(Presence.class)); SparkManager.getSessionManager().getConnection().addPacketListener(workspacePresenceListener, new PacketTypeFilter(Presence.class));
// Send Available status // Send Available status
final Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence(); final Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
SparkManager.getSessionManager().changePresence(presence); SparkManager.getSessionManager().changePresence(presence);
// Until we have better plugin management, will init after presence updates. // Until we have better plugin management, will init after presence updates.
gatewayPlugin = new GatewayPlugin(); gatewayPlugin = new GatewayPlugin();
gatewayPlugin.initialize(); gatewayPlugin.initialize();
// Load all non-presence related items. // Load all non-presence related items.
conferences.loadConferenceBookmarks(); conferences.loadConferenceBookmarks();
SearchManager.getInstance(); SearchManager.getInstance();
transcriptPlugin = new ChatTranscriptPlugin(); transcriptPlugin = new ChatTranscriptPlugin();
// Load Broadcast Plugin // Load Broadcast Plugin
broadcastPlugin = new BroadcastPlugin(); broadcastPlugin = new BroadcastPlugin();
broadcastPlugin.initialize(); broadcastPlugin.initialize();
// Load BookmarkPlugin // Load BookmarkPlugin
bookmarkPlugin = new BookmarkPlugin(); bookmarkPlugin = new BookmarkPlugin();
bookmarkPlugin.initialize(); bookmarkPlugin.initialize();
// Schedule loading of the plugins after two seconds. // Schedule loading of the plugins after two seconds.
TaskEngine.getInstance().schedule(new TimerTask() { TaskEngine.getInstance().schedule(new TimerTask() {
public void run() { public void run() {
final PluginManager pluginManager = PluginManager.getInstance(); final PluginManager pluginManager = PluginManager.getInstance();
pluginManager.loadPlugins(); pluginManager.loadPlugins();
pluginManager.initializePlugins(); pluginManager.initializePlugins();
// Subscriptions are always manual // Subscriptions are always manual
Roster roster = SparkManager.getConnection().getRoster(); Roster roster = SparkManager.getConnection().getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.manual); roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
} }
}, 2000); }, 2000);
// Check URI Mappings // Check URI Mappings
SparkManager.getChatManager().handleURIMapping(Spark.ARGUMENTS); SparkManager.getChatManager().handleURIMapping(Spark.ARGUMENTS);
} }
/** /**
* Returns the status box for the User. * Returns the status box for the User.
* *
* @return the status box for the user. * @return the status box for the user.
*/ */
public StatusBar getStatusBar() { public StatusBar getStatusBar() {
return statusBox; return statusBox;
} }
/** /**
* This is to handle agent to agent conversations. * This is to handle agent to agent conversations.
* *
* @param packet the smack packet to process. * @param packet the smack packet to process.
*/ */
public void processPacket(final Packet packet) { public void processPacket(final Packet packet) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
handleIncomingPacket(packet); handleIncomingPacket(packet);
} }
}); });
} }
private void handleIncomingPacket(Packet packet) { private void handleIncomingPacket(Packet packet) {
// We only handle message packets here. // We only handle message packets here.
if (packet instanceof Message) { if (packet instanceof Message) {
final Message message = (Message)packet; final Message message = (Message)packet;
boolean isGroupChat = message.getType() == Message.Type.groupchat; boolean isGroupChat = message.getType() == Message.Type.groupchat;
// Check if Conference invite. If so, do not handle here. // Check if Conference invite. If so, do not handle here.
if (message.getExtension("x", "jabber:x:conference") != null) { if (message.getExtension("x", "jabber:x:conference") != null) {
return; return;
} }
final String body = message.getBody(); final String body = message.getBody();
boolean broadcast = message.getProperty("broadcast") != null; boolean broadcast = message.getProperty("broadcast") != null;
// Handle offline message. // Handle offline message.
DelayInformation offlineInformation = (DelayInformation)message.getExtension("x", "jabber:x:delay"); DelayInformation offlineInformation = (DelayInformation)message.getExtension("x", "jabber:x:delay");
if (offlineInformation != null && (Message.Type.chat == message.getType() || if (offlineInformation != null && (Message.Type.chat == message.getType() ||
Message.Type.normal == message.getType())) { Message.Type.normal == message.getType())) {
handleOfflineMessage(message); handleOfflineMessage(message);
} }
if (body == null || if (body == null ||
isGroupChat || isGroupChat ||
broadcast || broadcast ||
message.getType() == Message.Type.normal || message.getType() == Message.Type.normal ||
message.getType() == Message.Type.headline || message.getType() == Message.Type.headline ||
message.getType() == Message.Type.error) { message.getType() == Message.Type.error) {
return; return;
} }
// Create new chat room for Agent Invite. // Create new chat room for Agent Invite.
final String from = packet.getFrom(); final String from = packet.getFrom();
final String host = SparkManager.getSessionManager().getServerAddress(); final String host = SparkManager.getSessionManager().getServerAddress();
// Don't allow workgroup notifications to come through here. // Don't allow workgroup notifications to come through here.
final String bareJID = StringUtils.parseBareAddress(from); final String bareJID = StringUtils.parseBareAddress(from);
if (host.equalsIgnoreCase(from) || from == null) { if (host.equalsIgnoreCase(from) || from == null) {
return; return;
} }
ChatRoom room = null; ChatRoom room = null;
try { try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID); room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} }
catch (ChatRoomNotFoundException e) { catch (ChatRoomNotFoundException e) {
// Ignore // Ignore
} }
// Check for non-existent rooms. // Check for non-existent rooms.
if (room == null) { if (room == null) {
createOneToOneRoom(bareJID, message); createOneToOneRoom(bareJID, message);
} }
} }
} }
/** /**
* Creates a new room if necessary and inserts an offline message. * Creates a new room if necessary and inserts an offline message.
* *
* @param message The Offline message. * @param message The Offline message.
*/ */
private void handleOfflineMessage(Message message) { private void handleOfflineMessage(Message message) {
if(!ModelUtil.hasLength(message.getBody())){ if(!ModelUtil.hasLength(message.getBody())){
return; return;
} }
String bareJID = StringUtils.parseBareAddress(message.getFrom()); String bareJID = StringUtils.parseBareAddress(message.getFrom());
ContactItem contact = contactList.getContactItemByJID(bareJID); ContactItem contact = contactList.getContactItemByJID(bareJID);
String nickname = StringUtils.parseName(bareJID); String nickname = StringUtils.parseName(bareJID);
if (contact != null) { if (contact != null) {
nickname = contact.getDisplayName(); nickname = contact.getDisplayName();
} }
// Create the room if it does not exist. // Create the room if it does not exist.
ChatRoom room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname); ChatRoom room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
if(!SparkManager.getChatManager().getChatContainer().getChatFrame().isVisible())
// Insert offline message {
room.getTranscriptWindow().insertMessage(nickname, message, ChatManager.FROM_COLOR, Color.white); SparkManager.getChatManager().getChatContainer().getChatFrame().setVisible(true);
room.addToTranscript(message, true); }
// Send display and notified message back. // Insert offline message
SparkManager.getMessageEventManager().sendDeliveredNotification(message.getFrom(), message.getPacketID()); room.getTranscriptWindow().insertMessage(nickname, message, ChatManager.FROM_COLOR, Color.white);
SparkManager.getMessageEventManager().sendDisplayedNotification(message.getFrom(), message.getPacketID()); room.addToTranscript(message, true);
}
// Send display and notified message back.
/** SparkManager.getMessageEventManager().sendDeliveredNotification(message.getFrom(), message.getPacketID());
* Creates a new room based on an anonymous user. SparkManager.getMessageEventManager().sendDisplayedNotification(message.getFrom(), message.getPacketID());
* }
* @param bareJID the bareJID of the anonymous user.
* @param message the message from the anonymous user. /**
*/ * Creates a new room based on an anonymous user.
private void createOneToOneRoom(String bareJID, Message message) { *
ContactItem contact = contactList.getContactItemByJID(bareJID); * @param bareJID the bareJID of the anonymous user.
String nickname = StringUtils.parseName(bareJID); * @param message the message from the anonymous user.
if (contact != null) { */
nickname = contact.getDisplayName(); private void createOneToOneRoom(String bareJID, Message message) {
} ContactItem contact = contactList.getContactItemByJID(bareJID);
else { String nickname = StringUtils.parseName(bareJID);
// Attempt to load VCard from users who we are not subscribed to. if (contact != null) {
VCard vCard = SparkManager.getVCardManager().getVCard(bareJID); nickname = contact.getDisplayName();
if (vCard != null && vCard.getError() == null) { }
String firstName = vCard.getFirstName(); else {
String lastName = vCard.getLastName(); // Attempt to load VCard from users who we are not subscribed to.
String userNickname = vCard.getNickName(); VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
if (ModelUtil.hasLength(userNickname)) { if (vCard != null && vCard.getError() == null) {
nickname = userNickname; String firstName = vCard.getFirstName();
} String lastName = vCard.getLastName();
else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) { String userNickname = vCard.getNickName();
nickname = firstName + " " + lastName; if (ModelUtil.hasLength(userNickname)) {
} nickname = userNickname;
else if (ModelUtil.hasLength(firstName)) { }
nickname = firstName; 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) { SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
Log.error("Could not find chat room.", e); try {
} insertMessage(bareJID, message);
} }
catch (ChatRoomNotFoundException e) {
Log.error("Could not find chat room.", e);
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); private void insertMessage(final String bareJID, final Message message) throws ChatRoomNotFoundException {
chatRoom.getChatInputEditor().requestFocusInWindow(); ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} chatRoom.insertMessage(message);
int chatLength = chatRoom.getTranscriptWindow().getDocument().getLength();
chatRoom.getTranscriptWindow().setCaretPosition(chatLength);
/** chatRoom.getChatInputEditor().requestFocusInWindow();
* Returns the Workspace TabbedPane. If you wish to add your }
* component, simply use addTab( name, icon, component ) call.
*
* @return the workspace JideTabbedPane /**
*/ * Returns the Workspace TabbedPane. If you wish to add your
public SparkTabbedPane getWorkspacePane() { * component, simply use addTab( name, icon, component ) call.
return workspacePane; *
} * @return the workspace JideTabbedPane
*/
public SparkTabbedPane getWorkspacePane() {
/** return workspacePane;
* Returns the <code>ContactList</code> associated with this workspace. }
*
* @return the ContactList associated with this workspace.
*/ /**
public ContactList getContactList() { * Returns the <code>ContactList</code> associated with this workspace.
return contactList; *
} * @return the ContactList associated with this workspace.
*/
public void changeCardLayout(String layout) { public ContactList getContactList() {
cardLayout.show(cardPanel, layout); return contactList;
} }
public JPanel getCardPanel() { public void changeCardLayout(String layout) {
return cardPanel; cardLayout.show(cardPanel, layout);
} }
/** public JPanel getCardPanel() {
* Returns the <code>CommandPanel</code> of this Workspace. return cardPanel;
* }
* @return the CommandPanel.
*/ /**
public CommandPanel getCommandPanel() { * Returns the <code>CommandPanel</code> of this Workspace.
return commandPanel; *
} * @return the CommandPanel.
*/
public ChatTranscriptPlugin getTranscriptPlugin() { public CommandPanel getCommandPanel() {
return transcriptPlugin; return commandPanel;
} }
}
public ChatTranscriptPlugin getTranscriptPlugin() {
return transcriptPlugin;
}
}