Commit fc9346b0 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-190] Fixed up MSN typing notifications to cancel if inactive.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7485 b35dd754-fafc-0310-a699-88a17e54d16e
parent abdc5f1e
......@@ -23,6 +23,9 @@ import net.sf.jml.message.MsnDatacastMessage;
import net.sf.jml.message.MsnUnknownMessage;
import java.util.Date;
import java.util.TimerTask;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
/**
* MSN Listener Interface.
......@@ -41,6 +44,8 @@ public class MSNListener extends MsnAdapter {
*/
public MSNListener(MSNSession session) {
this.msnSession = session;
sessionReaper = new SessionReaper();
timer.schedule(sessionReaper, reaperInterval, reaperInterval);
}
/**
......@@ -48,6 +53,26 @@ public class MSNListener extends MsnAdapter {
*/
public MSNSession msnSession = null;
/**
* Timer to check for stale typing notifications.
*/
private Timer timer = new Timer();
/**
* Interval at which typing notifications are reaped.
*/
private int reaperInterval = 5000; // 5 seconds
/**
* The actual repear task.
*/
private SessionReaper sessionReaper;
/**
* Record of active typing notifications.
*/
private ConcurrentHashMap<String,Date> typingNotificationMap = new ConcurrentHashMap<String,Date>();
/**
* Handles incoming messages from MSN users.
*/
......@@ -82,6 +107,7 @@ public class MSNListener extends MsnAdapter {
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().convertIDToJID(friend.getEmail().toString())
);
typingNotificationMap.put(friend.getEmail().toString(), new Date());
}
else {
Log.debug("MSN: Received unknown control msg to " + switchboard + " from " + friend + ": " + message);
......@@ -317,4 +343,31 @@ public class MSNListener extends MsnAdapter {
}
}
/**
* Clean up any active typing notifications that are stale.
*/
private class SessionReaper extends TimerTask {
/**
* Silence any typing notifications that are stale.
*/
public void run() {
cancelTypingNotifications();
}
}
/**
* Any typing notification that hasn't been heard in 10 seconds will be killed.
*/
private void cancelTypingNotifications() {
for (String source : typingNotificationMap.keySet()) {
if (typingNotificationMap.get(source).getTime() < ((new Date().getTime()) - 10000)) {
msnSession.getTransport().sendChatInactiveNotification(
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().convertIDToJID(source)
);
typingNotificationMap.remove(source);
}
}
}
}
......@@ -397,7 +397,9 @@ public class MSNSession extends TransportSession {
public void sendChatState(JID jid, ChatStateType chatState) {
Email jidEmail = Email.parseStr(getTransport().convertJIDToID(jid));
MsnControlMessage mcm = new MsnControlMessage();
if (chatState.equals(ChatStateType.composing)) {
mcm.setTypingUser(msnMessenger.getOwner().getEmail().getEmailAddress());
}
for (MsnSwitchboard sb : msnMessenger.getActiveSwitchboards()) {
if (sb.containContact(jidEmail)) {
sb.sendMessage(mcm, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment