use of org.jivesoftware.spark.ui.ChatContainer 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;
}
}
});
}
use of org.jivesoftware.spark.ui.ChatContainer in project Spark by igniterealtime.
the class CallManager method getSparkTab.
/**
* Returns the <code>SparkTab</code> that acts as a container to this PhonePanel.
*
* @param phonePanel the <code>PhonePanel</code>
* @return the SparkTab.
*/
public SparkTab getSparkTab(PhonePanel phonePanel) {
final ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
int tabCount = chatContainer.getTabCount();
for (int i = 0; i < tabCount; i++) {
SparkTab sparkTab = chatContainer.getTabAt(i);
Component containerComponent = chatContainer.getComponentInTab(sparkTab);
if (containerComponent.equals(phonePanel)) {
return sparkTab;
}
if (containerComponent instanceof ChatRoom) {
ChatRoom chatRoom = (ChatRoom) containerComponent;
Component rightComponent = chatRoom.getSplitPane().getRightComponent();
if (phonePanel.equals(rightComponent)) {
return sparkTab;
}
}
}
return null;
}
use of org.jivesoftware.spark.ui.ChatContainer in project Spark by igniterealtime.
the class UserSearchResults method openChatRoom.
private void openChatRoom(int row) {
String jid = (String) resultsTable.getValueAt(row, 0);
String nickname = XmppStringUtils.parseLocalpart(jid);
TableColumn column;
try {
column = resultsTable.getColumn("nick");
int col = column.getModelIndex();
nickname = (String) resultsTable.getValueAt(row, col);
if (!ModelUtil.hasLength(nickname)) {
nickname = XmppStringUtils.parseLocalpart(jid);
}
} catch (Exception e1) {
// Ignore e1
}
ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
ChatContainer chatRooms = chatManager.getChatContainer();
chatRooms.activateChatRoom(chatRoom);
}
use of org.jivesoftware.spark.ui.ChatContainer 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();
}
use of org.jivesoftware.spark.ui.ChatContainer 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);
}
Aggregations