From 01219cd341023a83a1940e66bbb375683e7e70e3 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 4 Nov 2002 20:06:15 +0000 Subject: [PATCH] Added ChatterValidator interface to validate usernames before they can be added to the 'chatters' list. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1889 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/client/ChatDirector.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 5377034fa..594b1f089 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.37 2002/10/31 23:27:16 mdb Exp $ +// $Id: ChatDirector.java,v 1.38 2002/11/04 20:06:15 ray Exp $ package com.threerings.crowd.chat; @@ -41,6 +41,17 @@ public class ChatDirector extends BasicDirector public void chattersUpdated (Iterator chatternames); } + /** + * A validator for adding usernames to the chatter list. + */ + public static interface ChatterValidator + { + /** + * Returns true if the username can be added to the chatters list. + */ + public boolean isChatterValid (String username); + } + /** * Creates a chat director and initializes it with the supplied * context. The chat director will register itself as a location @@ -133,11 +144,26 @@ public class ChatDirector extends BasicDirector _chatterObservers.remove(co); } + /** + * Sets the validator that decides if a username is valid to be + * added to the chatter list, or null if no such filtering is desired. + */ + public void setChatterValidator (ChatterValidator validator) + { + _chatterValidator = validator; + } + /** * Adds a chatter to our list of recent chatters. */ protected void addChatter (String name) { + // check to see if the chatter validator approves.. + if ((_chatterValidator != null) && + (!_chatterValidator.isChatterValid(name))) { + return; + } + boolean wasthere = _chatters.remove(name); _chatters.addFirst(name); @@ -603,6 +629,9 @@ public class ChatDirector extends BasicDirector /** An optionally present mutelist director. */ protected MuteDirector _muter; + /** Validator of who may be added to the chatters list. */ + protected ChatterValidator _chatterValidator; + /** Usernames of users we've recently chatted with. */ protected LinkedList _chatters = new LinkedList();