From 7982e21fc18e716e364dbb6f7ea8ab1fdf75847a Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 28 Jun 2002 04:09:39 +0000 Subject: [PATCH] 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 --- .../crowd/chat/client/ChatDirector.java | 31 ++++++++- .../crowd/chat/client/MuteDirector.java | 65 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/java/com/threerings/crowd/chat/client/MuteDirector.java diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index b8cc39a60..31f53c6ae 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -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; @@ -42,6 +42,15 @@ public class ChatDirector _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 * 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) { + if (isBlocked(source)) { + return; + } + // pass this on to our chat displays for (int i = 0; i < _displays.size(); i++) { ChatDisplay display = (ChatDisplay)_displays.get(i); @@ -308,6 +321,10 @@ public class ChatDirector protected void handleSpeakMessage (String type, Object[] args) { String speaker = (String)args[0]; + if (isBlocked(speaker)) { + return; + } + String bundle = null; String message = null; @@ -354,6 +371,15 @@ public class ChatDirector 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. */ protected CrowdContext _ctx; @@ -369,4 +395,7 @@ public class ChatDirector /** A mapping from auxiliary chat objects to the types under which * they are registered. */ protected HashIntMap _auxes = new HashIntMap(); + + /** An optionally present mutelist director. */ + protected MuteDirector _muter; } diff --git a/src/java/com/threerings/crowd/chat/client/MuteDirector.java b/src/java/com/threerings/crowd/chat/client/MuteDirector.java new file mode 100644 index 000000000..48589a18d --- /dev/null +++ b/src/java/com/threerings/crowd/chat/client/MuteDirector.java @@ -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(); +}