mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Roar updates:
- When joining a groupchat, old messages will no longer popup - import cleanups in RosterDialog.java and PluginManager.java git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12430 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
committed by
wolf.posdorfer
parent
247bf52f3b
commit
891a7580d5
Binary file not shown.
@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jivesoftware.spark;
|
package org.jivesoftware.spark;
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -48,8 +47,6 @@ import org.dom4j.Element;
|
|||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
import org.jivesoftware.MainWindowListener;
|
import org.jivesoftware.MainWindowListener;
|
||||||
import org.jivesoftware.Spark;
|
import org.jivesoftware.Spark;
|
||||||
import org.jivesoftware.resource.Res;
|
|
||||||
import org.jivesoftware.resource.SparkRes;
|
|
||||||
import org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane;
|
import org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane;
|
||||||
import org.jivesoftware.spark.plugin.Plugin;
|
import org.jivesoftware.spark.plugin.Plugin;
|
||||||
import org.jivesoftware.spark.plugin.PluginClassLoader;
|
import org.jivesoftware.spark.plugin.PluginClassLoader;
|
||||||
|
|||||||
@ -33,8 +33,6 @@ import java.awt.event.FocusEvent;
|
|||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
|
||||||
import java.beans.PropertyChangeListener;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
@ -81,4 +81,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<property name="pluginsstuff" value="${basedir}\..\..\..\target\build\plugins"/>
|
||||||
|
|
||||||
|
<target name="copy" depends="jar">
|
||||||
|
|
||||||
|
<echo message="${pluginsstuff}"/>
|
||||||
|
|
||||||
|
<copy todir="${pluginsstuff}">
|
||||||
|
<fileset file="${spark.build}/plugins/roar.jar"/>
|
||||||
|
</copy>
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -19,9 +19,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.jivesoftware.spark.roar;
|
package org.jivesoftware.spark.roar;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import javax.swing.JFrame;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
import org.jivesoftware.spark.SparkManager;
|
||||||
import org.jivesoftware.spark.roar.displaytype.RoarDisplayType;
|
import org.jivesoftware.spark.roar.displaytype.RoarDisplayType;
|
||||||
import org.jivesoftware.spark.ui.ChatRoom;
|
import org.jivesoftware.spark.ui.ChatRoom;
|
||||||
|
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
|
||||||
import org.jivesoftware.spark.ui.GlobalMessageListener;
|
import org.jivesoftware.spark.ui.GlobalMessageListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +46,91 @@ public class RoarMessageListener implements GlobalMessageListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChatRoom room, Message message) {
|
public void messageReceived(ChatRoom room, Message message) {
|
||||||
_displaytype.messageReceived(room, message);
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
ChatRoom activeroom = SparkManager.getChatManager()
|
||||||
|
.getChatContainer().getActiveChatRoom();
|
||||||
|
|
||||||
|
int framestate = SparkManager.getChatManager().getChatContainer()
|
||||||
|
.getChatFrame().getState();
|
||||||
|
|
||||||
|
boolean isoldgroupchat = isOldGroupchat(message);
|
||||||
|
|
||||||
|
if (framestate == JFrame.NORMAL && activeroom.equals(room)
|
||||||
|
&& room.isShowing() && isoldgroupchat) {
|
||||||
|
// Do Nothing
|
||||||
|
} else {
|
||||||
|
_displaytype.messageReceived(room, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ChatRoomNotFoundException e) {
|
||||||
|
// i dont care
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the Messages come from a time prior entering the groupchat
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* @return true if this is an old Message
|
||||||
|
*/
|
||||||
|
private boolean isOldGroupchat(Message message) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|
||||||
|
int day = cal.get(Calendar.DATE);
|
||||||
|
int month = cal.get(Calendar.MONTH) + 1;
|
||||||
|
int year = cal.get(Calendar.YEAR);
|
||||||
|
|
||||||
|
StringBuilder build = new StringBuilder();
|
||||||
|
// Append leading 0's to hour,minute,seconds
|
||||||
|
build.append(year);
|
||||||
|
build.append(month < 10 ? "0" + month : month);
|
||||||
|
build.append(day < 10 ? "0" + day : day);
|
||||||
|
|
||||||
|
int todaysDate = Integer.parseInt(build.toString());
|
||||||
|
|
||||||
|
// Append leading 0's to hour,minute,seconds
|
||||||
|
String hour = cal.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
|
||||||
|
+ cal.get(Calendar.HOUR_OF_DAY) : ""
|
||||||
|
+ cal.get(Calendar.HOUR_OF_DAY);
|
||||||
|
String minute = cal.get(Calendar.MINUTE) < 10 ? "0"
|
||||||
|
+ cal.get(Calendar.MINUTE) : "" + cal.get(Calendar.MINUTE);
|
||||||
|
String second = cal.get(Calendar.SECOND) < 10 ? "0"
|
||||||
|
+ cal.get(Calendar.SECOND) : "" + cal.get(Calendar.SECOND);
|
||||||
|
|
||||||
|
int todaysHour = Integer.parseInt(hour + minute + second);
|
||||||
|
|
||||||
|
String stamp = "";
|
||||||
|
|
||||||
|
// get String with timestamp
|
||||||
|
// 20110526T08:27:18
|
||||||
|
if (message.toXML().contains("stamp=")) {
|
||||||
|
stamp = extractDate(message.toXML());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isoldgroupchat = false;
|
||||||
|
|
||||||
|
if (stamp.length() > 0) {
|
||||||
|
// 20110526T08:27:18
|
||||||
|
// split into 20110526
|
||||||
|
// and 08:27:18
|
||||||
|
String[] split = stamp.split("T");
|
||||||
|
int dateFromMessage = Integer.parseInt(split[0]);
|
||||||
|
|
||||||
|
int hourFromMessage = Integer.parseInt(split[1].replace(":", ""));
|
||||||
|
|
||||||
|
// if dateFromMessage < todaysDate it is an old Chat
|
||||||
|
isoldgroupchat = dateFromMessage < todaysDate;
|
||||||
|
|
||||||
|
// if is still not old chat
|
||||||
|
if (!isoldgroupchat) {
|
||||||
|
// check if the time from Message < time now
|
||||||
|
isoldgroupchat = hourFromMessage < todaysHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return isoldgroupchat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,5 +138,18 @@ public class RoarMessageListener implements GlobalMessageListener {
|
|||||||
_displaytype.messageSent(room, message);
|
_displaytype.messageSent(room, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the time stamp from a given xmpp packet
|
||||||
|
*
|
||||||
|
* @param xmlstring
|
||||||
|
* @return String like <b>20110526T08:27:18</b>, split at "T"
|
||||||
|
*/
|
||||||
|
public String extractDate(String xmlstring) {
|
||||||
|
int indexofstamp = xmlstring.indexOf("stamp=");
|
||||||
|
String result = xmlstring
|
||||||
|
.substring(indexofstamp + 7, indexofstamp + 24);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user