From 09c7229fa6115f83cda610230598f891a22956aa Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Mon, 9 Nov 2009 20:31:46 +0000 Subject: [PATCH] Add channel-based communications to the chat history logs as well. This groud work for msoy issue 286, which has probably been around since the channel system was added. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5990 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/data/UserMessage.java | 35 ++++++++++++------- .../crowd/chat/server/ChatChannelManager.java | 20 ++++++++++- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/data/UserMessage.java b/src/java/com/threerings/crowd/chat/data/UserMessage.java index e4ce7b2a0..1f6483b68 100644 --- a/src/java/com/threerings/crowd/chat/data/UserMessage.java +++ b/src/java/com/threerings/crowd/chat/data/UserMessage.java @@ -34,6 +34,9 @@ public class UserMessage extends ChatMessage /** The mode of the message. @see ChatCodes.DEFAULT_MODE */ public byte mode; + /** The channel of the message, or null if not set. */ + public ChatChannel channel; + /** * For unserialization. */ @@ -41,25 +44,33 @@ public class UserMessage extends ChatMessage { } - /** - * Construct a user message. - */ - public UserMessage (Name speaker, String bundle, String message, byte mode) - { - super(message, bundle); - this.speaker = speaker; - this.mode = mode; - } - /** * Constructs a user message for a player originated tell (which has no bundle and is in the * default mode). */ public UserMessage (Name speaker, String message) { - super(message, null); + this(speaker, null, message, ChatCodes.DEFAULT_MODE); + } + + /** + * Construct a user message. + */ + public UserMessage (Name speaker, String bundle, String message, byte mode) + { + this(null, speaker, bundle, message, mode); + } + + /** + * Construct a user message that was spoken using the channel system. + */ + public UserMessage ( + ChatChannel channel, Name speaker, String bundle, String message, byte mode) + { + super(message, bundle); + this.channel = channel; this.speaker = speaker; - this.mode = ChatCodes.DEFAULT_MODE; + this.mode = mode; } /** diff --git a/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java b/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java index ae2a3af24..425bc3162 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java +++ b/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java @@ -85,7 +85,7 @@ public abstract class ChatChannelManager public void speak (ClientObject caller, final ChatChannel channel, String message, byte mode) { final UserMessage umsg = new UserMessage( - ((BodyObject)caller).getVisibleName(), null, message, mode); + intern(channel), ((BodyObject)caller).getVisibleName(), null, message, mode); // if we're hosting this channel, dispatch it directly if (_channels.containsKey(channel)) { @@ -169,6 +169,7 @@ public abstract class ChatChannelManager { // map the participants of our now resolved channel ChannelInfo info = new ChannelInfo(); + info.channel = channel; info.participants = parts; _channels.put(channel, info); @@ -243,6 +244,7 @@ public abstract class ChatChannelManager for (int bodyId : bodyIds) { BodyObject bobj = getBodyObject(bodyId); if (bobj != null && shouldDeliverSpeak(channel, message, bobj)) { + SpeakUtil.recordToChatHistory(message, bobj.username); bobj.postMessage(ChatCodes.CHAT_CHANNEL_NOTIFICATION, channel, message); } } @@ -275,6 +277,19 @@ public abstract class ChatChannelManager return true; } + /** + * Returns a widely referenced instance equivalent to the given channel, if one is available. + * This reduces memory usage since clients send new channel instances with each message. + */ + protected ChatChannel intern (ChatChannel channel) + { + ChannelInfo chinfo = _channels.get(channel); + if (chinfo != null) { + return chinfo.channel; + } + return channel; + } + /** * Converts a speaker's visible name into a unique integer id. This is not the oid for this * speaker but rather a persistent integer identifier that can be passed between servers and @@ -371,6 +386,9 @@ public abstract class ChatChannelManager /** Contains metadata for a particular channel. */ protected static class ChannelInfo { + /** The channel this info is for. */ + public ChatChannel channel; + /** The body ids of the participants of this channel. */ public IntSet participants;