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
This commit is contained in:
Charlie Groves
2009-06-17 00:07:24 +00:00
parent 09b965dae5
commit 501e62616c
2 changed files with 21 additions and 3 deletions
@@ -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
{
}
@@ -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<ChatMessage> getChatHistory (Name username)
{
List<ChatMessage> 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<ChatMessage> 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<ChatMessage> getHistoryList (Name username)
{
if (username instanceof KeepNoHistory) {
return null;
}
List<ChatMessage> history = _histories.get(username);
if (history == null) {
_histories.put(username, history = Lists.newArrayList());