diff --git a/src/as/com/threerings/crowd/chat/client/ChatDirector.as b/src/as/com/threerings/crowd/chat/client/ChatDirector.as index d6ba3c4d3..a93ad1657 100644 --- a/src/as/com/threerings/crowd/chat/client/ChatDirector.as +++ b/src/as/com/threerings/crowd/chat/client/ChatDirector.as @@ -44,7 +44,6 @@ import com.threerings.util.MessageManager; import com.threerings.util.Name; import com.threerings.util.TimeUtil; -import com.threerings.crowd.client.LocationObserver; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.CrowdCodes; import com.threerings.crowd.data.PlaceObject; @@ -64,15 +63,13 @@ import com.threerings.crowd.chat.data.UserSystemMessage; * place constrained chat as well as direct messaging. */ public class ChatDirector extends BasicDirector - implements LocationObserver, MessageListener + implements MessageListener { // statically reference classes we require ChatMarshaller; /** - * Creates a chat director and initializes it with the supplied context. The chat director will - * register itself as a location observer so that it can automatically process place - * constrained chat. + * Creates a chat director and initializes it with the supplied context. * * @param msgmgr the message manager via which we do our translations. * @param bundle the message bundle from which we obtain our chat-related translation strings. @@ -86,11 +83,8 @@ public class ChatDirector extends BasicDirector _msgmgr = msgmgr; _bundle = bundle; - // register ourselves as a location observer - _cctx.getLocationDirector().addLocationObserver(this); - if (_bundle == null || _msgmgr == null) { - Log.getLog(this).warning("Null bundle or message manager given to ChatDirector"); + log.warning("Null bundle or message manager given to ChatDirector"); return; } var msg :MessageBundle = _msgmgr.getBundle(_bundle); @@ -564,32 +558,38 @@ public class ChatDirector extends BasicDirector return mogrifyChatImpl(text, false, true); } - // documentation inherited from interface LocationObserver - public function locationMayChange (placeId :int) :Boolean + /** + * Called by a LocationDirector when we enter a new location to configure our place chat. + */ + public function enteredLocation (place :PlaceObject) :void { - // we accept all location change requests - return true; - } + if (place == null) { + log.warning("enteredLocation must be passed a non-null place object!"); + return; + } - // documentation inherited from interface LocationObserver - public function locationDidChange (place :PlaceObject) :void - { + // nix our old location if we have one if (_place != null) { - // unlisten to our old object - _place.removeListener(this); + leftLocation(_place); } // listen to the new object _place = place; - if (_place != null) { - _place.addListener(this); - } + _place.addListener(this); } - // documentation inherited from interface LocationObserver - public function locationChangeFailed (placeId :int, reason :String) :void + /** + * Called by a LocationDirector when we leave our current place. + */ + public function leftLocation (place :PlaceObject) :void { - // nothing we care about + // if this is our current place chat, then stop listening to it + if (place == _place) { + _place.removeListener(this); + _place = null; + } else { + log.warning("leftLocation called with unknown place?", "have", _place, "left", place); + } } // documentation inherited from interface MessageListener @@ -649,8 +649,7 @@ public class ChatDirector extends BasicDirector _chatters.length = 0; notifyChatterObservers(); - // clear the _place - locationDidChange(null); + // the location director will call leftLocation() when we logoff // clear our service _cservice = null; @@ -942,8 +941,8 @@ public class ChatDirector extends BasicDirector if (bundle != null && _msgmgr != null) { var msgb :MessageBundle = _msgmgr.getBundle(bundle); if (msgb == null) { - Log.getLog(this).warning("No message bundle available to translate message " + - "[bundle=" + bundle + ", message=" + message + "]."); + log.warning("No message bundle available to translate message", + "bundle", bundle, "message", message); } else { message = msgb.xlate(message); } @@ -1001,6 +1000,9 @@ public class ChatDirector extends BasicDirector return true; } + /** Log this! */ + protected const log :Log = Log.getLog(this); + /** Our active chat context. */ protected var _cctx :CrowdContext; diff --git a/src/as/com/threerings/crowd/client/LocationDirector.as b/src/as/com/threerings/crowd/client/LocationDirector.as index 9441f06f3..af500db9a 100644 --- a/src/as/com/threerings/crowd/client/LocationDirector.as +++ b/src/as/com/threerings/crowd/client/LocationDirector.as @@ -332,6 +332,9 @@ public class LocationDirector extends BasicDirector _controller = null; } + // let the chat director know that we're leaving this place + _cctx.getChatDirector().leftLocation(_plobj); + // unsubscribe from our old place object _cctx.getDObjectManager().unsubscribeFromObject(_plobj.getOid(), this); _plobj = null; @@ -467,6 +470,9 @@ public class LocationDirector extends BasicDirector } } + // let the chat director know that we're entering this place + _cctx.getChatDirector().enteredLocation(_plobj); + // let our observers know that all is well on the western front _observers.apply(didChangeOp); } @@ -558,8 +564,7 @@ public class LocationDirector extends BasicDirector /** The place controller in effect for our current place. */ protected var _controller :PlaceController; - /** The oid of the place for which we have an outstanding moveTo request, or -1 if we have no - * outstanding request. */ + /** The place oid to whihc we have an outstanding moveTo request, or -1 if we have none. */ protected var _pendingPlaceId :int = -1; /** The oid of the place we previously occupied. */ @@ -574,8 +579,7 @@ public class LocationDirector extends BasicDirector /** A listener that wants to know if we succeeded or how we failed to move. */ protected var _moveListener :ResultListener; - /** We require that a moveTo request be outstanding for one minute before it is declared to be - * stale. */ + /** Allow a moveTo request be outstanding for one minute before it is declared to be stale. */ protected static const STALE_REQUEST_DURATION :int = 60 * 1000; } }