From 501e62616c74524e9433b6f03f5fc7925143b17b Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Wed, 17 Jun 2009 00:07:24 +0000 Subject: [PATCH] Add a marker interface that Names can implement to indicate to SpeakUtil that they don't need chat history git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5826 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/server/KeepNoHistory.java | 9 +++++++++ .../threerings/crowd/chat/server/SpeakUtil.java | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/java/com/threerings/crowd/chat/server/KeepNoHistory.java diff --git a/src/java/com/threerings/crowd/chat/server/KeepNoHistory.java b/src/java/com/threerings/crowd/chat/server/KeepNoHistory.java new file mode 100644 index 000000000..8eb8875d2 --- /dev/null +++ b/src/java/com/threerings/crowd/chat/server/KeepNoHistory.java @@ -0,0 +1,9 @@ +package com.threerings.crowd.chat.server; + +/** + * Marks a {@link Name} as disinterested in chat history such that {@link SpeakUtil} will keep no + * messages sent to it. + */ +public interface KeepNoHistory +{ +} diff --git a/src/java/com/threerings/crowd/chat/server/SpeakUtil.java b/src/java/com/threerings/crowd/chat/server/SpeakUtil.java index d15b0387a..3021b0a14 100644 --- a/src/java/com/threerings/crowd/chat/server/SpeakUtil.java +++ b/src/java/com/threerings/crowd/chat/server/SpeakUtil.java @@ -200,12 +200,14 @@ public class SpeakUtil /** * Returns a list of {@link ChatMessage} objects to which this user has been privy in the - * recent past. + * recent past. If the given name implements {@link KeepNoHistory}, null is returned. */ public static List getChatHistory (Name username) { List history = getHistoryList(username); - pruneHistory(System.currentTimeMillis(), history); + if (history != null) { + pruneHistory(System.currentTimeMillis(), history); + } return history; } @@ -232,6 +234,9 @@ public class SpeakUtil for (Name username : usernames) { // add the message to this user's chat history List history = getHistoryList(username); + if (history == null) { + continue; + } history.add(msg); // if the history is big enough, potentially prune it (we always prune when asked for @@ -270,10 +275,14 @@ public class SpeakUtil } /** - * Returns this user's chat history, creating one if necessary. + * Returns this user's chat history, creating one if necessary. If the given name implements + * {@link KeepNoHistory}, null is returned. */ protected static List getHistoryList (Name username) { + if (username instanceof KeepNoHistory) { + return null; + } List history = _histories.get(username); if (history == null) { _histories.put(username, history = Lists.newArrayList());