diff --git a/core/src/main/java/com/threerings/crowd/chat/data/SpeakObject.java b/core/src/main/java/com/threerings/crowd/chat/data/SpeakObject.java index 52e848248..b5a327183 100644 --- a/core/src/main/java/com/threerings/crowd/chat/data/SpeakObject.java +++ b/core/src/main/java/com/threerings/crowd/chat/data/SpeakObject.java @@ -21,6 +21,8 @@ package com.threerings.crowd.chat.data; +import com.threerings.presents.dobj.DObject; + import com.threerings.util.Name; /** @@ -33,12 +35,17 @@ public interface SpeakObject public static interface ListenerOp { /** Call this method if you only have access to body oids. */ - void apply (int bodyOid); + void apply (SpeakObject sender, int bodyOid); /** Call this method if you can provide usernames directly. */ - void apply (Name username); + void apply (SpeakObject sender, Name username); } + /** + * Returns an identifier for what type of chat this speak object represents. + */ + String getChatIdentifier (); + /** * The speak service will call this every time a chat message is delivered on this speak object * to note the listeners that received the message. diff --git a/core/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java b/core/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java index efd7b0eb6..a18b41442 100644 --- a/core/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java +++ b/core/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java @@ -334,7 +334,7 @@ public abstract class ChatChannelManager for (int bodyId : bodyIds) { BodyObject bobj = getBodyObject(bodyId); if (bobj != null && shouldDeliverSpeak(channel, message, bobj)) { - _chatHistory.record(channel, message, bobj.getVisibleName()); + _chatHistory.record(channel, bobj.getChatIdentifier(), message, bobj.getVisibleName()); bobj.postMessage(ChatCodes.CHAT_CHANNEL_NOTIFICATION, channel, message); } } diff --git a/core/src/main/java/com/threerings/crowd/chat/server/ChatHistory.java b/core/src/main/java/com/threerings/crowd/chat/server/ChatHistory.java index f1743896b..ef020a095 100644 --- a/core/src/main/java/com/threerings/crowd/chat/server/ChatHistory.java +++ b/core/src/main/java/com/threerings/crowd/chat/server/ChatHistory.java @@ -67,9 +67,13 @@ public class ChatHistory /** The message sent. */ public final ChatMessage message; - public Entry (ChatChannel channel, ChatMessage message) { + /** The source of the sent message. */ + public final String source; + + public Entry (ChatChannel channel, String source, ChatMessage message) { this.channel = channel; this.message = message; + this.source = source; } public void writeObject (ObjectOutputStream out) throws IOException { @@ -91,8 +95,8 @@ public class ChatHistory public ChatHistory () { SpeakUtil.registerMessageObserver(new SpeakUtil.MessageObserver() { - public void messageDelivered (Name hearer, UserMessage message) { - record(null, message, hearer); + public void messageDelivered (String source, Name hearer, UserMessage message) { + record(null, source, message, hearer); } }); } @@ -136,20 +140,21 @@ public class ChatHistory * Records the specified channel and message to the specified users' chat histories. If {@link * ChatMessage#timestamp} is not already filled in, it will be. */ - public void record (ChatChannel channel, UserMessage msg, Name ...usernames) + public void record (ChatChannel channel, String source, UserMessage msg, Name ...usernames) { // fill in the message's time stamp if necessary if (msg.timestamp == 0L) { msg.timestamp = System.currentTimeMillis(); } - Entry entry = new Entry(channel, msg); + Entry entry = new Entry(channel, source, msg); for (Name username : usernames) { // add the message to this user's chat history List history = getList(username); if (history == null) { continue; } + history.add(entry); // if the history is big enough, potentially prune it (we always prune when asked for diff --git a/core/src/main/java/com/threerings/crowd/chat/server/ChatProvider.java b/core/src/main/java/com/threerings/crowd/chat/server/ChatProvider.java index 439cb15f6..6631d868a 100644 --- a/core/src/main/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/core/src/main/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -263,7 +263,7 @@ public class ChatProvider SpeakUtil.sendMessage(target, message); // note that the teller "heard" what they said - SpeakUtil.noteMessage(message.speaker, message); + SpeakUtil.noteMessage(target, message.speaker, message); } /** diff --git a/core/src/main/java/com/threerings/crowd/chat/server/SpeakUtil.java b/core/src/main/java/com/threerings/crowd/chat/server/SpeakUtil.java index ba64fb374..c43d620aa 100644 --- a/core/src/main/java/com/threerings/crowd/chat/server/SpeakUtil.java +++ b/core/src/main/java/com/threerings/crowd/chat/server/SpeakUtil.java @@ -51,7 +51,7 @@ public class SpeakUtil /** * Called for each player that hears a particular chat message. */ - void messageDelivered (Name hearer, UserMessage message); + void messageDelivered (String source, Name hearer, UserMessage message); } /** @@ -196,7 +196,7 @@ public class SpeakUtil * Notes that the specified user was privy to the specified message. If {@link * ChatMessage#timestamp} is not already filled in, it will be. */ - protected static void noteMessage (Name username, UserMessage msg) + protected static void noteMessage (SpeakObject sender, Name username, UserMessage msg) { // fill in the message's time stamp if necessary if (msg.timestamp == 0L) { @@ -206,7 +206,7 @@ public class SpeakUtil // Log.info("Noted that " + username + " heard " + msg + "."); // notify any message observers - _messageOp.init(username, msg); + _messageOp.init(sender, username, msg); _messageObs.apply(_messageOp); } @@ -224,15 +224,15 @@ public class SpeakUtil public RootDObjectManager omgr; public UserMessage message; - public void apply (int bodyOid) { + public void apply (SpeakObject sender, int bodyOid) { DObject dobj = omgr.getObject(bodyOid); if (dobj != null && dobj instanceof BodyObject) { - noteMessage(((BodyObject)dobj).getVisibleName(), message); + noteMessage(sender, ((BodyObject)dobj).getVisibleName(), message); } } - public void apply (Name username) { - noteMessage(username, message); + public void apply (SpeakObject sender, Name username) { + noteMessage(sender, username, message); } } @@ -240,16 +240,18 @@ public class SpeakUtil protected static class MessageObserverOp implements ObserverList.ObserverOp { - public void init (Name hearer, UserMessage message) { + public void init (SpeakObject sender, Name hearer, UserMessage message) { _hearer = hearer; _message = message; + _sender = sender; } public boolean apply (MessageObserver observer) { - observer.messageDelivered(_hearer, _message); + observer.messageDelivered(_sender.getChatIdentifier(), _hearer, _message); return true; } + protected SpeakObject _sender; protected Name _hearer; protected UserMessage _message; } diff --git a/core/src/main/java/com/threerings/crowd/data/BodyObject.java b/core/src/main/java/com/threerings/crowd/data/BodyObject.java index 1ed0deab5..435ac07ff 100644 --- a/core/src/main/java/com/threerings/crowd/data/BodyObject.java +++ b/core/src/main/java/com/threerings/crowd/data/BodyObject.java @@ -127,7 +127,13 @@ public class BodyObject extends ClientObject // from interface SpeakObject public void applyToListeners (ListenerOp op) { - op.apply(getVisibleName()); + op.apply(this, getVisibleName()); + } + + // from interface SpeakObject + public String getChatIdentifier () + { + return "default"; } /** diff --git a/core/src/main/java/com/threerings/crowd/data/PlaceObject.java b/core/src/main/java/com/threerings/crowd/data/PlaceObject.java index 645627e5c..fdf3f7f1d 100644 --- a/core/src/main/java/com/threerings/crowd/data/PlaceObject.java +++ b/core/src/main/java/com/threerings/crowd/data/PlaceObject.java @@ -30,6 +30,7 @@ import com.threerings.presents.dobj.DSet; import com.threerings.presents.dobj.OidList; import com.threerings.presents.dobj.ServerMessageEvent; +import com.threerings.crowd.chat.data.ChatCodes; import com.threerings.crowd.chat.data.SpeakMarshaller; import com.threerings.crowd.chat.data.SpeakObject; @@ -149,10 +150,16 @@ public class PlaceObject extends DObject public void applyToListeners (ListenerOp op) { for (int ii = 0, ll = occupants.size(); ii < ll; ii++) { - op.apply(occupants.get(ii)); + op.apply(this, occupants.get(ii)); } } + // documentation inherited + public String getChatIdentifier () + { + return "default"; + } + // AUTO-GENERATED: METHODS START /** * Requests that oid be added to the occupants