Modified chat services to support auxilliary chat objects with associated

types. Chat messages arriving on the auxilliary chat objects will be
tagged with the type that was associated with said objects when they were
registered with the chat director and chat displays can then render those
chat messages accordingly.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@807 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-16 21:46:46 +00:00
parent 178639e0c8
commit 0a920a9b75
3 changed files with 69 additions and 12 deletions
@@ -1,9 +1,10 @@
//
// $Id: ChatDirector.java,v 1.13 2001/12/16 21:02:57 mdb Exp $
// $Id: ChatDirector.java,v 1.14 2001/12/16 21:46:46 mdb Exp $
package com.threerings.crowd.chat;
import java.util.ArrayList;
import com.samskivert.util.HashIntMap;
import com.threerings.presents.client.*;
import com.threerings.presents.dobj.*;
@@ -117,9 +118,10 @@ public class ChatDirector
* to this object and will remain subscribed to it for as long as it
* remains in effect as an auxilliary chat source.
*/
public void addAuxilliarySource (DObject source)
public void addAuxilliarySource (String type, DObject source)
{
source.addListener(this);
_auxes.put(source.getOid(), type);
}
/**
@@ -128,6 +130,7 @@ public class ChatDirector
public void removeAuxilliarySource (DObject source)
{
source.removeListener(this);
_auxes.remove(source.getOid());
}
// documentation inherited
@@ -161,9 +164,9 @@ public class ChatDirector
{
String name = event.getName();
if (name.equals(ChatService.SPEAK_NOTIFICATION)) {
handleSpeakMessage(event.getArgs());
handleSpeakMessage(getType(event.getTargetOid()), event.getArgs());
} else if (name.equals(ChatService.SYSTEM_NOTIFICATION)) {
handleSystemMessage(event.getArgs());
handleSystemMessage(getType(event.getTargetOid()), event.getArgs());
}
}
@@ -209,7 +212,16 @@ public class ChatDirector
}
}
protected void handleSpeakMessage (Object[] args)
/**
* Called when a speak message is received on the place object or one
* of our auxilliary chat objects.
*
* @param type {@link ChatCodes#PLACE_CHAT_TYPE} if the message was
* received on the place object or the type associated with the
* auxilliary chat object on which the message was received.
* @param args the arguments provided with the speak notification.
*/
protected void handleSpeakMessage (String type, Object[] args)
{
String speaker = (String)args[0];
String message = (String)args[1];
@@ -217,22 +229,51 @@ public class ChatDirector
// pass this on to our chat displays
for (int i = 0; i < _displays.size(); i++) {
ChatDisplay display = (ChatDisplay)_displays.get(i);
display.displaySpeakMessage(speaker, message);
display.displaySpeakMessage(type, speaker, message);
}
}
protected void handleSystemMessage (Object[] args)
/**
* Called when a system message is delivered on one of our chat
* objects.
*
* @param type {@link ChatCodes#PLACE_CHAT_TYPE} if the message was
* received on the place object or the type associated with the
* auxilliary chat object on which the message was received.
* @param args the arguments provided with the system message
* notification.
*/
protected void handleSystemMessage (String type, Object[] args)
{
String message = (String)args[0];
// pass this on to our chat displays
for (int i = 0; i < _displays.size(); i++) {
ChatDisplay display = (ChatDisplay)_displays.get(i);
display.displaySystemMessage(message);
display.displaySystemMessage(type, message);
}
}
/**
* Looks up and returns the message type associated with the specified
* oid.
*/
protected String getType (int oid)
{
String type = (String)_auxes.get(oid);
return (type == null) ? PLACE_CHAT_TYPE : type;
}
/** Our active chat context. */
protected CrowdContext _ctx;
/** The place object that we currently occupy. */
protected PlaceObject _place;
/** A list of registered chat displays. */
protected ArrayList _displays = new ArrayList();
/** A mapping from auxilliary chat objects to the types under which
* they are registered. */
protected HashIntMap _auxes = new HashIntMap();
}
@@ -1,5 +1,5 @@
//
// $Id: ChatDisplay.java,v 1.4 2001/10/18 23:55:24 mdb Exp $
// $Id: ChatDisplay.java,v 1.5 2001/12/16 21:46:46 mdb Exp $
package com.threerings.crowd.chat;
@@ -17,10 +17,15 @@ public interface ChatDisplay
* method after the speak message is accepted by the server and
* broadcast to everyone in the place.
*
* @param type {@link ChatCodes.PLACE_CHAT_TYPE} for a speak message
* delivered via the place object, or for messages delivered via an
* auxilliary chat object, the type code provided when that auxilliary
* object was registered.
* @param speaker the username of the speaker.
* @param message the text of the message.
*/
public void displaySpeakMessage (String speaker, String message);
public void displaySpeakMessage (
String type, String speaker, String message);
/**
* Called to display a tell message. A tell message is one that is
@@ -39,9 +44,13 @@ public interface ChatDisplay
* server and should be displayed visually differently from speak
* messages.
*
* @param type {@link ChatCodes.PLACE_CHAT_TYPE} for a speak message
* delivered via the place object, or for messages delivered via an
* auxilliary chat object, the type code provided when that auxilliary
* object was registered.
* @param message the text of the message.
*/
public void displaySystemMessage (String message);
public void displaySystemMessage (String type, String message);
/**
* Called in response to a chat request (either speak or tell) that
@@ -1,5 +1,5 @@
//
// $Id: ChatCodes.java,v 1.3 2001/10/18 23:55:24 mdb Exp $
// $Id: ChatCodes.java,v 1.4 2001/12/16 21:46:46 mdb Exp $
package com.threerings.crowd.chat;
@@ -13,6 +13,13 @@ public interface ChatCodes extends InvocationCodes
/** The module name for the chat services. */
public static final String MODULE_NAME = "chat";
/** The chat type code for chat messages delivered on the place object
* currently occupied by the client. This is the only type of chat
* message that will be delivered unless the chat director is
* explicitly provided with other chat message sources via {@link
* ChatDirector#addAuxilliarySource}. */
public static final String PLACE_CHAT_TYPE = "placeChat";
/** The message identifier for a speak request message. */
public static final String SPEAK_REQUEST = "spkreq";