Added a primitive mute director to get the ball rolling.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1554 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ChatDirector.java,v 1.23 2002/06/19 23:12:48 ray Exp $
|
// $Id: ChatDirector.java,v 1.24 2002/06/28 04:09:39 ray Exp $
|
||||||
|
|
||||||
package com.threerings.crowd.chat;
|
package com.threerings.crowd.chat;
|
||||||
|
|
||||||
@@ -42,6 +42,15 @@ public class ChatDirector
|
|||||||
_ctx.getLocationDirector().addLocationObserver(this);
|
_ctx.getLocationDirector().addLocationObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the mute director, if one is desired.
|
||||||
|
*/
|
||||||
|
public void setMuteDirector (MuteDirector muter)
|
||||||
|
{
|
||||||
|
_muter = muter;
|
||||||
|
addChatValidator(_muter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the supplied chat display to the chat display list. It will
|
* Adds the supplied chat display to the chat display list. It will
|
||||||
* subsequently be notified of incoming chat messages as well as tell
|
* subsequently be notified of incoming chat messages as well as tell
|
||||||
@@ -243,6 +252,10 @@ public class ChatDirector
|
|||||||
*/
|
*/
|
||||||
public void handleTellNotification (String source, String message)
|
public void handleTellNotification (String source, String message)
|
||||||
{
|
{
|
||||||
|
if (isBlocked(source)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// pass this on to our chat displays
|
// pass this on to our chat displays
|
||||||
for (int i = 0; i < _displays.size(); i++) {
|
for (int i = 0; i < _displays.size(); i++) {
|
||||||
ChatDisplay display = (ChatDisplay)_displays.get(i);
|
ChatDisplay display = (ChatDisplay)_displays.get(i);
|
||||||
@@ -308,6 +321,10 @@ public class ChatDirector
|
|||||||
protected void handleSpeakMessage (String type, Object[] args)
|
protected void handleSpeakMessage (String type, Object[] args)
|
||||||
{
|
{
|
||||||
String speaker = (String)args[0];
|
String speaker = (String)args[0];
|
||||||
|
if (isBlocked(speaker)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String bundle = null;
|
String bundle = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
|
|
||||||
@@ -354,6 +371,15 @@ public class ChatDirector
|
|||||||
return (type == null) ? PLACE_CHAT_TYPE : type;
|
return (type == null) ? PLACE_CHAT_TYPE : type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do an internal check to see if we can distribute chat from the
|
||||||
|
* specified user.
|
||||||
|
*/
|
||||||
|
protected boolean isBlocked (String username)
|
||||||
|
{
|
||||||
|
return (_muter != null) && _muter.isMuted(username);
|
||||||
|
}
|
||||||
|
|
||||||
/** Our active chat context. */
|
/** Our active chat context. */
|
||||||
protected CrowdContext _ctx;
|
protected CrowdContext _ctx;
|
||||||
|
|
||||||
@@ -369,4 +395,7 @@ public class ChatDirector
|
|||||||
/** A mapping from auxiliary chat objects to the types under which
|
/** A mapping from auxiliary chat objects to the types under which
|
||||||
* they are registered. */
|
* they are registered. */
|
||||||
protected HashIntMap _auxes = new HashIntMap();
|
protected HashIntMap _auxes = new HashIntMap();
|
||||||
|
|
||||||
|
/** An optionally present mutelist director. */
|
||||||
|
protected MuteDirector _muter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// $Id: MuteDirector.java,v 1.1 2002/06/28 04:09:39 ray Exp $
|
||||||
|
|
||||||
|
package com.threerings.crowd.chat;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import com.threerings.crowd.util.CrowdContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the mutelist.
|
||||||
|
*
|
||||||
|
* TODO: This class right now is pretty much just a placeholder.
|
||||||
|
*/
|
||||||
|
public class MuteDirector
|
||||||
|
implements ChatValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Should be instantiated after the ChatDirector.
|
||||||
|
*/
|
||||||
|
public MuteDirector (CrowdContext ctx)
|
||||||
|
{
|
||||||
|
// nothing to initialize right now
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the specified user is muted.
|
||||||
|
*/
|
||||||
|
public boolean isMuted (String username)
|
||||||
|
{
|
||||||
|
return _mutelist.contains(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mute or unmute the specified user.
|
||||||
|
*/
|
||||||
|
public void setMuted (String username, boolean mute)
|
||||||
|
{
|
||||||
|
if (mute) {
|
||||||
|
_mutelist.add(username);
|
||||||
|
} else {
|
||||||
|
_mutelist.remove(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface ChatValidator
|
||||||
|
public boolean validateSpeak (String msg)
|
||||||
|
{
|
||||||
|
return true; // sure!
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface ChatValidator
|
||||||
|
public boolean validateTell (String target, String msg)
|
||||||
|
{
|
||||||
|
if (isMuted(target)) {
|
||||||
|
// TODO: give user feedback on why the TELL is cancelled
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; // let it go through..
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The mutelist. */
|
||||||
|
protected HashSet _mutelist = new HashSet();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user