From b6b7a35c66e8c701037f74bdb601daf991c25359 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Wed, 10 Jan 2007 22:23:40 +0000 Subject: [PATCH] Fix ChatTranscript issue with current conversations. git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@6650 b35dd754-fafc-0310-a699-88a17e54d16e --- build/installer/spark.install4j | 381 ++++++++++++++---- build/projects/Spark.iml | 2 +- build/projects/Spark.ipr | 1 + .../jivesoftware/spark/ui/ChatContainer.java | 8 +- .../org/jivesoftware/spark/ui/ChatRoom.java | 9 + .../spark/ui/rooms/ChatRoomImpl.java | 1 + .../plugin/transcripts/ChatTranscripts.java | 46 ++- 7 files changed, 346 insertions(+), 102 deletions(-) diff --git a/build/installer/spark.install4j b/build/installer/spark.install4j index 412d9907..1cce0ee3 100644 --- a/build/installer/spark.install4j +++ b/build/installer/spark.install4j @@ -1,7 +1,11 @@ - + - + + + + + @@ -9,8 +13,8 @@ - - + + @@ -23,11 +27,12 @@ + - + - + @@ -36,22 +41,17 @@ - - - + + + - + - - - - - - + @@ -64,112 +64,343 @@ + + + + - - - + + + - + - - - - - - + + + + + - - + + - - - - - - - + + + + + + + + + + + - - - + + + + + + + ../../documentation/LICENSE.html + + + + + + + + + - - + + + + + + + + + + - - + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${compiler:sys.fullName} + + + + + + + + + + + + ${compiler:sys.fullName} ${compiler:sys.version} + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + context.getBooleanVariable("executeLauncherAction") && (!context.isUnattended()) + + + + + + + + + ${i18n:RunEntryExec("${compiler:sys.fullName}")} + + + true + + + executeLauncherAction + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - + + - - - - - + + + - + + - - - - - + + + + + + - - + + - - - + + + + - - - - + + + + - - + + diff --git a/build/projects/Spark.iml b/build/projects/Spark.iml index 75a1e8b8..247a6620 100644 --- a/build/projects/Spark.iml +++ b/build/projects/Spark.iml @@ -202,7 +202,7 @@ - + diff --git a/build/projects/Spark.ipr b/build/projects/Spark.ipr index d0b3d7ee..e1d7ebdf 100644 --- a/build/projects/Spark.ipr +++ b/build/projects/Spark.ipr @@ -404,6 +404,7 @@ + diff --git a/src/java/org/jivesoftware/spark/ui/ChatContainer.java b/src/java/org/jivesoftware/spark/ui/ChatContainer.java index 28f0bdcd..d717b9de 100644 --- a/src/java/org/jivesoftware/spark/ui/ChatContainer.java +++ b/src/java/org/jivesoftware/spark/ui/ChatContainer.java @@ -123,7 +123,7 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C public void allTabsRemoved() { chatFrame.setTitle(""); - chatFrame.setVisible(false); + chatFrame.dispose(); } }); @@ -384,7 +384,7 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C } else if (!chatFrame.isVisible()) { if (Spark.isWindows()) { - //chatFrame.setFocusableWindowState(false); + chatFrame.setFocusableWindowState(false); chatFrame.setState(Frame.ICONIFIED); } chatFrame.setVisible(true); @@ -640,7 +640,7 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C } else if (!chatFrame.isVisible()) { if (Spark.isWindows()) { - //chatFrame.setFocusableWindowState(false); + chatFrame.setFocusableWindowState(false); chatFrame.setState(Frame.ICONIFIED); } chatFrame.setVisible(true); @@ -723,7 +723,7 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C if (getTabCount() == 0) { chatFrame.setTitle(""); - chatFrame.setVisible(false); + chatFrame.dispose(); } this.removeTabAt(location); diff --git a/src/java/org/jivesoftware/spark/ui/ChatRoom.java b/src/java/org/jivesoftware/spark/ui/ChatRoom.java index 8a006dc5..5868c7c4 100644 --- a/src/java/org/jivesoftware/spark/ui/ChatRoom.java +++ b/src/java/org/jivesoftware/spark/ui/ChatRoom.java @@ -368,6 +368,15 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener scrollToBottom(); } + public void addToTranscript(String to, String from, String body, Date date) { + final Message newMessage = new Message(); + newMessage.setTo(to); + newMessage.setFrom(from); + newMessage.setBody(body); + newMessage.setProperty("date", date); + transcript.add(newMessage); + } + /** * Scrolls the chat window to the bottom. */ diff --git a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java index 92523a0f..c1879c7e 100644 --- a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java +++ b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java @@ -659,6 +659,7 @@ public class ChatRoomImpl extends ChatRoom { String nickname = StringUtils.parseName(from); Date date = message.getDate(); getTranscriptWindow().insertHistoryMessage(nickname, message.getBody(), date); + addToTranscript(message.getTo(), message.getFrom(), message.getBody(), date); } } diff --git a/src/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java b/src/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java index 22ac4c2e..ffc5fcf7 100644 --- a/src/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java +++ b/src/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java @@ -11,8 +11,8 @@ package org.jivesoftware.sparkimpl.plugin.transcripts; import org.jivesoftware.spark.SparkManager; -import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.StringUtils; +import org.jivesoftware.spark.util.log.Log; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; @@ -60,18 +60,18 @@ final public class ChatTranscripts { final File transcriptFile = getTranscriptFile(jid); // Write Full Transcript - writeToFile(transcriptFile, transcript.getMessages()); + writeToFile(transcriptFile, transcript.getMessages(), true); // Write to current history File final File currentHistoryFile = getCurrentHistoryFile(jid); - writeToFile(currentHistoryFile, transcript.getNumberOfEntries(20)); + writeToFile(currentHistoryFile, transcript.getNumberOfEntries(20), false); } - private static void writeToFile(File transcriptFile, Collection messages) { + private static void writeToFile(File transcriptFile, Collection messages, boolean append) { final StringBuilder builder = new StringBuilder(); // Handle new transcript file. - if (!transcriptFile.exists()) { + if (!transcriptFile.exists() || !append) { builder.append(""); } @@ -86,12 +86,12 @@ final public class ChatTranscripts { builder.append(""); } - if (!transcriptFile.exists()) { + if (!transcriptFile.exists() || !append) { builder.append(""); } - if (!transcriptFile.exists()) { + if (!transcriptFile.exists() || !append) { // Write out new File try { FileOutputStream fout = new FileOutputStream(transcriptFile); @@ -105,23 +105,25 @@ final public class ChatTranscripts { return; } - // Append to File - try { - final RandomAccessFile raf = new RandomAccessFile(transcriptFile, "rw"); + if (append) { + // Append to File + try { + final RandomAccessFile raf = new RandomAccessFile(transcriptFile, "rw"); - // We want to append near the end of the document as the last - // child in the transcript. - final String endTag = ""; - builder.append(endTag); - - raf.seek(transcriptFile.length() - endTag.length()); + // We want to append near the end of the document as the last + // child in the transcript. + final String endTag = ""; + builder.append(endTag); - // Append to the end - raf.writeBytes(builder.toString()); - raf.close(); - } - catch (IOException e) { - Log.error(e); + raf.seek(transcriptFile.length() - endTag.length()); + + // Append to the end + raf.writeBytes(builder.toString()); + raf.close(); + } + catch (IOException e) { + Log.error(e); + } } }