From f53975fe74b5692d8c7d23e3153ff0cf5334ea9d Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Wed, 17 Jul 2002 20:53:31 +0000 Subject: [PATCH] Cache tell request information in the chat director and pass it along to the various chat displays once we've ascertained success or failure. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1586 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/client/ChatDirector.java | 47 +++++++++++++++---- .../crowd/chat/client/ChatDisplay.java | 40 ++++++++++------ .../threerings/micasa/client/ChatPanel.java | 26 ++++++++-- 3 files changed, 85 insertions(+), 28 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 31f53c6ae..7a1c2fdb0 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -1,10 +1,12 @@ // -// $Id: ChatDirector.java,v 1.24 2002/06/28 04:09:39 ray Exp $ +// $Id: ChatDirector.java,v 1.25 2002/07/17 20:53:31 shaper Exp $ package com.threerings.crowd.chat; import java.util.ArrayList; + import com.samskivert.util.HashIntMap; +import com.samskivert.util.Tuple; import com.threerings.presents.client.*; import com.threerings.presents.dobj.*; @@ -143,8 +145,8 @@ public class ChatDirector } // make sure they can say what they want to say - for (int ii=0; ii < _validators.size(); ii++) { - if (!((ChatValidator) _validators.get(ii)).validateSpeak(message)) { + for (int ii = 0; ii < _validators.size(); ii++) { + if (!((ChatValidator)_validators.get(ii)).validateSpeak(message)) { return -1; } } @@ -177,13 +179,18 @@ public class ChatDirector public int requestTell (String target, String message) { // make sure they can say what they want to say - for (int ii=0; ii < _validators.size(); ii++) { - if (!((ChatValidator) _validators.get(ii)).validateTell(target, - message)) { + for (int ii = 0; ii < _validators.size(); ii++) { + if (!((ChatValidator)_validators.get(ii)).validateTell( + target, message)) { return -1; } } - return ChatService.tell(_ctx.getClient(), target, message, this); + + int invid = ChatService.tell(_ctx.getClient(), target, message, this); + // cache the tell info for use when reporting success or failure + // to our various chat displays + _tells.put(invid, new Tuple(target, message)); + return invid; } /** @@ -287,10 +294,19 @@ public class ChatDirector */ public void handleTellSucceeded (int invid) { + // remove the tell info for the successful request + Tuple tup = (Tuple)_tells.remove(invid); + if (tup == null) { + Log.warning("Notified of successful tell request but no " + + "tell info available [invid=" + invid + "]."); + return; + } + // pass this on to our chat displays + String target = (String)tup.left, message = (String)tup.right; for (int i = 0; i < _displays.size(); i++) { ChatDisplay display = (ChatDisplay)_displays.get(i); - display.handleResponse(invid, SUCCESS); + display.handleTellSucceeded(invid, target, message); } } @@ -302,10 +318,19 @@ public class ChatDirector */ public void handleTellFailed (int invid, String reason) { + // remove the tell info for the failed request + Tuple tup = (Tuple)_tells.remove(invid); + if (tup == null) { + Log.warning("Notified of failed tell request but no " + + "tell info available [invid=" + invid + "]."); + return; + } + // pass this on to our chat displays + String target = (String)tup.left; for (int i = 0; i < _displays.size(); i++) { ChatDisplay display = (ChatDisplay)_displays.get(i); - display.handleResponse(invid, reason); + display.handleTellFailed(invid, target, reason); } } @@ -398,4 +423,8 @@ public class ChatDirector /** An optionally present mutelist director. */ protected MuteDirector _muter; + + /** A cache of the target and message text associated with outstanding + * tell chat requests. */ + protected HashIntMap _tells = new HashIntMap(); } diff --git a/src/java/com/threerings/crowd/chat/client/ChatDisplay.java b/src/java/com/threerings/crowd/chat/client/ChatDisplay.java index cdb0f635d..e2faf40c0 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDisplay.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDisplay.java @@ -1,5 +1,5 @@ // -// $Id: ChatDisplay.java,v 1.9 2002/04/30 17:27:30 mdb Exp $ +// $Id: ChatDisplay.java,v 1.10 2002/07/17 20:53:31 shaper Exp $ package com.threerings.crowd.chat; @@ -65,23 +65,35 @@ public interface ChatDisplay String type, String bundle, String message); /** - * Called in response to a chat request (either speak or tell) that - * originated on this client. The request id supplied will match the - * one returned when the request was generated and the status will - * either indicate success (by being equal to SUCCESS) or - * failure (in which case it will contain a message failure code which - * can be converted into a displayable string). - * - *

A chat display should track outstanding chat requests so that - * it can properly handle the response when it arrives. + * Called in response to a successful tell request that originated on + * this client. The request id supplied will match the one returned + * when the request was generated, with the target and message + * detailing the target user name and tell message text associated + * with the request. * * @param reqid the request id of the request that resulted in this * response. - * @param status the message code indicating whether the chat request - * was successful or not. + * @param target the name of the user to whom the tell request was + * dispatched. + * @param message the text of the message. * - * @see ChatDirector#requestSpeak * @see ChatDirector#requestTell */ - public void handleResponse (int reqid, String status); + public void handleTellSucceeded (int reqid, String target, String message); + + /** + * Called in response to a failed tell request that originated on this + * client. The request id supplied will match the one returned when + * the request was generated, with the target and message detailing + * the target user name and tell message text associated with the + * request. + * + * @param reqid the request id of the request that resulted in this + * response. + * @param reason a translatable string explaining the reason for the + * tell request failure. + * + * @see ChatDirector#requestTell + */ + public void handleTellFailed (int reqid, String target, String reason); } diff --git a/src/java/com/threerings/micasa/client/ChatPanel.java b/src/java/com/threerings/micasa/client/ChatPanel.java index 0f5e0612f..a3d368358 100644 --- a/src/java/com/threerings/micasa/client/ChatPanel.java +++ b/src/java/com/threerings/micasa/client/ChatPanel.java @@ -1,5 +1,5 @@ // -// $Id: ChatPanel.java,v 1.14 2002/04/30 17:27:30 mdb Exp $ +// $Id: ChatPanel.java,v 1.15 2002/07/17 20:53:31 shaper Exp $ package com.threerings.micasa.client; @@ -318,14 +318,30 @@ public class ChatPanel } } - // documentation inherited - public void handleResponse (int reqid, String status) + // documentation inherited from interface + public void handleTellSucceeded (int reqid, String target, String message) { - if (!status.equals(ChatCodes.SUCCESS)) { - displayError(status); + // wrap the speaker in brackets + target = "[You whispered to " + target + "] "; + + // stick a newline on the message + message = message + "\n"; + + Document doc = _text.getDocument(); + try { + doc.insertString(doc.getLength(), target, _nameStyle); + doc.insertString(doc.getLength(), message, _msgStyle); + } catch (BadLocationException ble) { + Log.warning("Unable to insert text!? [error=" + ble + "]."); } } + // documentation inherited from interface + public void handleTellFailed (int reqid, String target, String reason) + { + displayError(reason); + } + public void willEnterPlace (PlaceObject place) { Log.info("We be here: " + place);