use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.
the class BroadcastPlugin method showAlert.
/**
* Show Server Alert.
*
* @param message the message to show.
* @param type
*/
private void showAlert(Message message) {
Type type = message.getType();
// Do not show alert if the message is an error.
if (message.getError() != null) {
return;
}
final String body = message.getBody();
String subject = message.getSubject();
StringBuilder buf = new StringBuilder();
if (subject != null) {
buf.append(Res.getString("subject")).append(": ").append(subject);
buf.append("\n\n");
}
buf.append(body);
String from = message.getFrom() != null ? message.getFrom() : "";
final TranscriptWindow window = new TranscriptWindow();
window.insertNotificationMessage(buf.toString(), ChatManager.TO_COLOR);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(window, BorderLayout.CENTER);
p.setBorder(BorderFactory.createLineBorder(Color.lightGray));
// Count the number of linebreaks <br> and \n
String s = message.getBody();
s = s.replace("<br/>", "\n");
s = s.replace("<br>", "\n");
int linebreaks = org.jivesoftware.spark.util.StringUtils.countNumberOfOccurences(s, '\n');
// Currently Serverbroadcasts dont contain Subjects, so this might be a MOTD message
boolean mightbeMOTD = message.getSubject() != null;
if (!from.contains("@")) {
// if theres no "@" it means the message came from the server
if (Default.getBoolean(Default.BROADCAST_IN_CHATWINDOW) || linebreaks > 20 || message.getBody().length() > 1000 || mightbeMOTD) {
// if we have more than 20 linebreaks or the message is longer
// than 1000characters we should broadcast
// in a normal chatwindow
broadcastInChat(message);
} else {
broadcastWithPanel(message);
}
} else if (message.getFrom() != null) {
userToUserBroadcast(message, type, from);
}
}
use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.
the class InviteSwingWorker method finished.
@Override
public void finished() {
final String roomName = XmppStringUtils.parseBareJid(roomJID);
try {
final ChatRoom room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
final TranscriptWindow transcriptWindow = room.getTranscriptWindow();
for (final String jid : (Set<String>) getValue()) {
final String notification = Res.getString("message.waiting.for.user.to.join", jid);
transcriptWindow.insertNotificationMessage(notification, ChatManager.NOTIFICATION_COLOR);
}
} catch (ChatRoomNotFoundException e) {
Log.error("Unable to identify chat room tab by name: " + roomName);
}
}
use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.
the class JinglePlugin method placeCall.
public void placeCall(String jid) throws SmackException {
// cancel call request if no Media Locator available
if (PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator()) {
return;
}
PhoneManager.setUsingMediaLocator(true);
jid = SparkManager.getUserManager().getFullJID(jid);
ChatRoom room = SparkManager.getChatManager().getChatRoom(XmppStringUtils.parseBareJid(jid));
if (JingleStateManager.getInstance().getJingleRoomState(room) != null) {
return;
}
SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
// Create a new Jingle Call with a full JID
JingleSession session = null;
try {
session = jingleManager.createOutgoingJingleSession(jid);
} catch (XMPPException e) {
Log.error(e);
}
TranscriptWindow transcriptWindow = room.getTranscriptWindow();
StyledDocument doc = (StyledDocument) transcriptWindow.getDocument();
Style style = doc.addStyle("StyleName", null);
OutgoingCall outgoingCall = new OutgoingCall();
outgoingCall.handleOutgoingCall(session, room, jid);
StyleConstants.setComponent(style, outgoingCall);
// Insert the image at the end of the text
try {
doc.insertString(doc.getLength(), "ignored text", style);
doc.insertString(doc.getLength(), "\n", null);
} catch (BadLocationException e) {
Log.error(e);
}
room.scrollToBottom();
}
use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.
the class SparkManager method printChatRoomTranscript.
/**
* Prints the transcript of a given chat room.
*
* @param room the chat room that contains the transcript to print.
*/
public static void printChatRoomTranscript(ChatRoom room) {
final ChatPrinter printer = new ChatPrinter();
final TranscriptWindow currentWindow = room.getTranscriptWindow();
if (currentWindow != null) {
printer.print(currentWindow);
}
}
use of org.jivesoftware.spark.ui.TranscriptWindow 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"));
}
Aggregations