use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl 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.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatContainer method handleRoomPresence.
/**
* Handles the presence of a one to one chat room.
*
* @param p the presence to handle.
*/
private void handleRoomPresence(final Presence p) {
final String roomname = XmppStringUtils.parseBareJid(p.getFrom());
ChatRoom chatRoom;
try {
chatRoom = getChatRoom(roomname);
} catch (ChatRoomNotFoundException e1) {
Log.debug("Could not locate chat room " + roomname);
return;
}
final String userid = XmppStringUtils.parseResource(p.getFrom());
if (p.getType() == Presence.Type.unavailable) {
fireUserHasLeft(chatRoom, userid);
} else if (p.getType() == Presence.Type.available) {
fireUserHasJoined(chatRoom, userid);
}
// Change tab icon
if (chatRoom instanceof ChatRoomImpl) {
// Notify state change.
int tabLoc = indexOfComponent(chatRoom);
if (tabLoc != -1) {
SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
}
}
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatContainer method addChatRoom.
/**
* Adds a new ChatRoom to Spark.
*
* @param room the ChatRoom to add.
*/
public synchronized void addChatRoom(final ChatRoom room) {
createFrameIfNeeded();
room.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(room.getRoomname()));
// Next, create a packet listener. We use an anonymous inner class for brevity.
StanzaListener myListener = stanza -> SwingUtilities.invokeLater(() -> handleRoomPresence((Presence) stanza));
room.registeredToFrame(chatFrame);
SparkManager.getConnection().addAsyncStanzaListener(myListener, presenceFilter);
// Add to PresenceMap
presenceMap.put(room.getRoomname(), myListener);
String tooltip;
if (room instanceof ChatRoomImpl) {
tooltip = ((ChatRoomImpl) room).getParticipantJID();
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(((ChatRoomImpl) room).getParticipantJID());
tooltip = "<html><body><b>Contact: </b>" + nickname + "<br><b>JID: </b>" + tooltip;
} else {
tooltip = room.getRoomname();
}
// Create ChatRoom UI and dock
SparkTab tab = addTab(room.getTabTitle(), room.getTabIcon(), room, tooltip);
tab.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
checkTabPopup(e);
}
public void mousePressed(MouseEvent e) {
checkTabPopup(e);
}
});
room.addMessageListener(this);
// Remove brand panel
final String title = getTabAt(0).getActualText();
if (title.equals(WELCOME_TITLE)) {
chatFrame.setTitle(room.getRoomTitle());
}
final TimerTask visibleTask = new SwingTimerTask() {
public void doRun() {
checkVisibility(room);
}
};
TaskEngine.getInstance().schedule(visibleTask, 100);
// Add to ChatRoomList
chatRoomList.add(room);
// Notify users that the chat room has been opened.
fireChatRoomOpened(room);
// Focus Chat
focusChat();
// Add Room listeners to override issue with input maps and keybinding on the mac.
if (Spark.isMac()) {
room.getChatInputEditor().addKeyListener(this);
}
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatManager method composingNotification.
public void composingNotification(final String from) {
SwingUtilities.invokeLater(() -> {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom;
try {
chatRoom = getChatContainer().getChatRoom(XmppStringUtils.parseBareJid(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
typingNotificationList.add(chatRoom);
// Notify Decorators
notifySparkTabHandlers(chatRoom);
((ChatRoomImpl) chatRoom).notifyChatStateChange(ChatState.composing);
}
} catch (ChatRoomNotFoundException e) {
// Do nothing
}
contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
});
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ConversationHistoryPlugin method addUserToHistory.
/**
* Adds the last user to the history tags.
*
* @param room the ChatRoom where the conversation took place.
*/
private void addUserToHistory(ChatRoom room) {
if (room instanceof ChatRoomImpl) {
ChatRoomImpl roomImpl = (ChatRoomImpl) room;
String jid = roomImpl.getParticipantJID();
jid = XmppStringUtils.parseBareJid(jid);
historyList.remove(jid);
historyList.add(0, jid);
}
}
Aggregations