Widen some, and break out chat histories a bit so that the server can

manually squirt messages into a chat history without actually sending
the message to the client.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4753 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Dave Hoover
2007-07-11 21:34:41 +00:00
parent 7896ee8c02
commit 26a2a6a052
@@ -64,8 +64,7 @@ public class SpeakProvider
* via the speak provider with which this validator was * via the speak provider with which this validator was
* registered. * registered.
*/ */
public boolean isValidSpeaker (DObject speakObj, ClientObject speaker, public boolean isValidSpeaker (DObject speakObj, ClientObject speaker, byte mode);
byte mode);
} }
/** /**
@@ -206,8 +205,7 @@ public class SpeakProvider
* client. * client.
* @param message the text of the message. * @param message the text of the message.
*/ */
public static void sendInfo ( public static void sendInfo (DObject speakObj, String bundle, String message)
DObject speakObj, String bundle, String message)
{ {
sendSystem(speakObj, bundle, message, SystemMessage.INFO); sendSystem(speakObj, bundle, message, SystemMessage.INFO);
} }
@@ -227,8 +225,7 @@ public class SpeakProvider
* client. * client.
* @param message the text of the message. * @param message the text of the message.
*/ */
public static void sendFeedback ( public static void sendFeedback (DObject speakObj, String bundle, String message)
DObject speakObj, String bundle, String message)
{ {
sendSystem(speakObj, bundle, message, SystemMessage.FEEDBACK); sendSystem(speakObj, bundle, message, SystemMessage.FEEDBACK);
} }
@@ -248,8 +245,7 @@ public class SpeakProvider
* client. * client.
* @param message the text of the message. * @param message the text of the message.
*/ */
public static void sendAttention ( public static void sendAttention (DObject speakObj, String bundle, String message)
DObject speakObj, String bundle, String message)
{ {
sendSystem(speakObj, bundle, message, SystemMessage.ATTENTION); sendSystem(speakObj, bundle, message, SystemMessage.ATTENTION);
} }
@@ -277,8 +273,7 @@ public class SpeakProvider
// post the message to the relevant object // post the message to the relevant object
speakObj.postMessage(CHAT_NOTIFICATION, new Object[] { msg }); speakObj.postMessage(CHAT_NOTIFICATION, new Object[] { msg });
// if this is a user message; add it to the heard history of all // if this is a user message; add it to the heard history of all users that can "hear" it
// users that can "hear" it
if (!(msg instanceof UserMessage)) { if (!(msg instanceof UserMessage)) {
return; return;
} else if (speakObj instanceof SpeakObject) { } else if (speakObj instanceof SpeakObject) {
@@ -322,16 +317,7 @@ public class SpeakProvider
msg.timestamp = System.currentTimeMillis(); msg.timestamp = System.currentTimeMillis();
} }
// add the message to this user's chat history recordToChatHistory(msg, username);
ArrayList<ChatMessage> history = getHistoryList(username);
history.add(msg);
// if the history is big enough, potentially prune it (we always
// prune when asked for the history, so this is just to balance
// memory usage with CPU expense)
if (history.size() > 15) {
pruneHistory(msg.timestamp, history);
}
// Log.info("Noted that " + username + " heard " + msg + "."); // Log.info("Noted that " + username + " heard " + msg + ".");
// notify any message observers // notify any message observers
@@ -339,6 +325,33 @@ public class SpeakProvider
_messageObs.apply(_messageOp); _messageObs.apply(_messageOp);
} }
/**
* Records the specified message to the specified users' chat histories.
* If {@link ChatMessage#timestamp} is not already filled in, it will be.
*/
public static void recordToChatHistory (UserMessage msg, Name... usernames)
{
// fill in the message's time stamp if necessary
if (msg.timestamp == 0L) {
msg.timestamp = System.currentTimeMillis();
}
for (int ii = 0; ii < usernames.length; ii ++ ) {
Name username = usernames[ii];
// add the message to this user's chat history
ArrayList<ChatMessage> history = getHistoryList(username);
history.add(msg);
// if the history is big enough, potentially prune it (we always
// prune when asked for the history, so this is just to balance
// memory usage with CPU expense)
if (history.size() > 15) {
pruneHistory(msg.timestamp, history);
}
}
}
/** /**
* Returns this user's chat history, creating one if necessary. * Returns this user's chat history, creating one if necessary.
*/ */
@@ -354,8 +367,7 @@ public class SpeakProvider
/** /**
* Prunes all messages from this history which are expired. * Prunes all messages from this history which are expired.
*/ */
protected static void pruneHistory ( protected static void pruneHistory (long now, ArrayList<ChatMessage> history)
long now, ArrayList<ChatMessage> history)
{ {
int prunepos = 0; int prunepos = 0;
for (int ll = history.size(); prunepos < ll; prunepos++) { for (int ll = history.size(); prunepos < ll; prunepos++) {