use of org.jivesoftware.spark.ui.ChatRoom 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.ChatRoom in project Spark by igniterealtime.
the class BuzzPlugin method initialize.
public void initialize() {
ProviderManager.addExtensionProvider(ELEMENTNAME, NAMESPACE, new BuzzPacket.Provider());
ProviderManager.addExtensionProvider(ELEMENTNAME_OLD, NAMESPACE_OLD, new BuzzPacket.Provider());
SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
if (stanza instanceof Message) {
final Message message = (Message) stanza;
boolean buzz = message.getExtension(ELEMENTNAME_OLD, NAMESPACE_OLD) != null || message.getExtension(ELEMENTNAME, NAMESPACE) != null;
if (buzz) {
SwingUtilities.invokeLater(() -> shakeWindow(message));
}
}
}, new StanzaTypeFilter(Message.class));
SparkManager.getChatManager().addChatRoomListener(new ChatRoomListener() {
public void chatRoomOpened(final ChatRoom room) {
TimerTask task = new SwingTimerTask() {
public void doRun() {
addBuzzFeatureToChatRoom(room);
}
};
TaskEngine.getInstance().schedule(task, 100);
}
public void chatRoomLeft(ChatRoom room) {
}
public void chatRoomClosed(ChatRoom room) {
}
public void chatRoomActivated(ChatRoom room) {
}
public void userHasJoined(ChatRoom room, String userid) {
}
public void userHasLeft(ChatRoom room, String userid) {
}
});
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class RosterMemberPanel method callEnded.
/**
* Called when the call is ended. This does basic container cleanup.
*/
public void callEnded() {
if (!callWasTransferred) {
historyPanel.callEnded();
setStatus("Call Ended", redColor);
}
hangUpButton.setEnabled(false);
hangUpButton.setOpaque(false);
muteButton.setEnabled(false);
muteButton.setOpaque(false);
holdButton.setEnabled(false);
holdButton.setOpaque(false);
transferButton.setEnabled(false);
setStatus("Call Ended", redColor);
// Add notification to ChatRoom if one exists.
final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
if (chatRoom != null) {
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
String time = formatter.format(new Date());
chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callendedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
}
// If this is a standalone phone call with no associated ChatRoom
// gray out title and show off-phone icon.
final ChatRoom room = callManager.getAssociatedChatRoom(this);
softPhone.addCallSession(room, SoftPhoneManager.CallRoomState.callWasEnded);
// Notify
SparkManager.getChatManager().notifySparkTabHandlers(room);
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class RosterMemberPanel method changeState.
private void changeState(SoftPhoneManager.CallRoomState state) {
final ChatRoom room = callManager.getAssociatedChatRoom(this);
softPhone.addCallSession(room, state);
SparkManager.getChatManager().notifySparkTabHandlers(room);
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class RosterMemberPanel method callStarted.
/**
* Called when a new call is established.
*/
private void callStarted() {
// Show History
historyPanel.removeAll();
historyPanel.addPreviousConversations(phoneNumber);
hangUpButton.setEnabled(true);
muteButton.setEnabled(true);
holdButton.setEnabled(true);
transferButton.setEnabled(true);
setStatus(CONNECTED, false);
// Add notification to ChatRoom if one exists.
final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
if (chatRoom != null) {
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
String time = formatter.format(new Date());
chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callstartedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
}
}
Aggregations