Expanding chat services that were ommitted earlier: filtering, chatters.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4472 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -137,45 +137,54 @@ public class ChatDirector extends BasicDirector
|
|||||||
* chat requests and receipts will be filtered with all filters
|
* chat requests and receipts will be filtered with all filters
|
||||||
* before they being sent or dispatched locally.
|
* before they being sent or dispatched locally.
|
||||||
*/
|
*/
|
||||||
// public void addChatFilter (ChatFilter filter)
|
public function addChatFilter (filter :ChatFilter) :void
|
||||||
// {
|
{
|
||||||
// _filters.add(filter);
|
_filters.add(filter);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified chat validator from the list of chat validators.
|
* Removes the specified chat validator from the list of chat validators.
|
||||||
*/
|
*/
|
||||||
// public void removeChatFilter (ChatFilter filter)
|
public function removeChatFilter (filter :ChatFilter) :void
|
||||||
// {
|
{
|
||||||
// _filters.remove(filter);
|
_filters.remove(filter);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an observer that watches the chatters list, and updates it
|
* Adds an observer that watches the chatters list, and updates it
|
||||||
* immediately.
|
* immediately.
|
||||||
*/
|
*/
|
||||||
// public void addChatterObserver (ChatterObserver co)
|
public function addChatterObserver (co :ChatterObserver) :void
|
||||||
// {
|
{
|
||||||
// _chatterObservers.add(co);
|
_chatterObservers.add(co);
|
||||||
// co.chattersUpdated(_chatters.listIterator());
|
co.chattersUpdated(_chatters);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an observer from the list of chatter observers.
|
* Removes an observer from the list of chatter observers.
|
||||||
*/
|
*/
|
||||||
// public void removeChatterObserver (ChatterObserver co)
|
public function removeChatterObserver (co :ChatterObserver) :void
|
||||||
// {
|
{
|
||||||
// _chatterObservers.remove(co);
|
_chatterObservers.remove(co);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the validator that decides if a username is valid to be
|
* 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.
|
* added to the chatter list, or null if no such filtering is desired.
|
||||||
*/
|
*/
|
||||||
// public void setChatterValidator (ChatterValidator validator)
|
public function setChatterValidator (validator :ChatterValidator) :void
|
||||||
// {
|
{
|
||||||
// _chatterValidator = validator;
|
_chatterValidator = validator;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of the recent users with whom we've chatted. The most recent
|
||||||
|
* users will be listed first.
|
||||||
|
*/
|
||||||
|
public function getChatters () :Array
|
||||||
|
{
|
||||||
|
return _chatters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a chat command handler.
|
* Registers a chat command handler.
|
||||||
@@ -537,13 +546,15 @@ public class ChatDirector extends BasicDirector
|
|||||||
* Run a message through all the currently registered filters.
|
* Run a message through all the currently registered filters.
|
||||||
*/
|
*/
|
||||||
public function filter (
|
public function filter (
|
||||||
msg :String, otherUser :Name, outgoing :Boolean) :String
|
msg :String, otherUser :Name, outgoing :Boolean) :String
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO: needs testing
|
||||||
|
_filters.apply(function (observer :ChatFilter) :void {
|
||||||
|
if (msg != null) {
|
||||||
|
msg = observer.filter(msg, otherUser, outgoing);
|
||||||
|
}
|
||||||
|
});
|
||||||
return msg;
|
return msg;
|
||||||
// _filterMessageOp.setMessage(msg, otherUser, outgoing);
|
|
||||||
// _filters.apply(_filterMessageOp);
|
|
||||||
// return _filterMessageOp.getMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -676,9 +687,9 @@ public class ChatDirector extends BasicDirector
|
|||||||
|
|
||||||
clearDisplays();
|
clearDisplays();
|
||||||
|
|
||||||
// // clear out the list of people we've chatted with
|
// clear out the list of people we've chatted with
|
||||||
// _chatters.clear();
|
_chatters.length = 0;
|
||||||
// notifyChatterObservers();
|
notifyChatterObservers();
|
||||||
|
|
||||||
// clear the _place
|
// clear the _place
|
||||||
locationDidChange(null);
|
locationDidChange(null);
|
||||||
@@ -890,38 +901,42 @@ public class ChatDirector extends BasicDirector
|
|||||||
*/
|
*/
|
||||||
protected function addChatter (name :Name) :void
|
protected function addChatter (name :Name) :void
|
||||||
{
|
{
|
||||||
// // check to see if the chatter validator approves..
|
// check to see if the chatter validator approves..
|
||||||
// if ((_chatterValidator != null) &&
|
if ((_chatterValidator != null) &&
|
||||||
// (!_chatterValidator.isChatterValid(name))) {
|
(!_chatterValidator.isChatterValid(name))) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// boolean wasthere = _chatters.remove(name);
|
var wasThere :Boolean = ArrayUtil.removeAll(_chatters, name);
|
||||||
// _chatters.addFirst(name);
|
_chatters.unshift(name);
|
||||||
//
|
|
||||||
// if (!wasthere) {
|
if (!wasThere) {
|
||||||
// if (_chatters.size() > MAX_CHATTERS) {
|
if (_chatters.length > MAX_CHATTERS) {
|
||||||
// _chatters.removeLast();
|
_chatters.length = MAX_CHATTERS; // truncate array
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// notifyChatterObservers();
|
// we only notify on a change to the contents, not just reordering
|
||||||
// }
|
notifyChatterObservers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies all registered {@link ChatterObserver}s that the list of
|
* Notifies all registered {@link ChatterObserver}s that the list of
|
||||||
* chatters has changed.
|
* chatters has changed.
|
||||||
*/
|
*/
|
||||||
// protected void notifyChatterObservers ()
|
protected function notifyChatterObservers () :void
|
||||||
// {
|
{
|
||||||
// _chatterObservers.apply(new ObserverList.ObserverOp() {
|
_chatterObservers.apply(chatterObserverNotify);
|
||||||
// public boolean apply (Object observer) {
|
}
|
||||||
// ((ChatterObserver)observer).chattersUpdated(
|
|
||||||
// _chatters.listIterator());
|
/**
|
||||||
// return true;
|
* A function to be called by our _chatterObservers list to apply
|
||||||
// }
|
* updates to each observer.
|
||||||
// });
|
*/
|
||||||
// }
|
protected function chatterObserverNotify (obs :ChatterObserver) :void
|
||||||
|
{
|
||||||
|
obs.chattersUpdated(_chatters);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates the specified message using the specified bundle.
|
* Translates the specified message using the specified bundle.
|
||||||
@@ -998,22 +1013,20 @@ public class ChatDirector extends BasicDirector
|
|||||||
protected var _displays :ObserverList = new ObserverList();
|
protected var _displays :ObserverList = new ObserverList();
|
||||||
|
|
||||||
/** A list of registered chat filters. */
|
/** A list of registered chat filters. */
|
||||||
// protected ObserverList _filters =
|
protected var _filters :ObserverList = new ObserverList();
|
||||||
// new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
|
|
||||||
|
|
||||||
/** 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 var _auxes :HashMap = new HashMap();
|
protected var _auxes :HashMap = new HashMap();
|
||||||
|
|
||||||
// /** Validator of who may be added to the chatters list. */
|
/** Validator of who may be added to the chatters list. */
|
||||||
// protected var _chatterValidator :ChatterValidator;
|
protected var _chatterValidator :ChatterValidator;
|
||||||
//
|
|
||||||
// /** Usernames of users we've recently chatted with. */
|
/** Usernames of users we've recently chatted with. */
|
||||||
// protected var _chatters :LinkedList = new LinkedList();
|
protected var _chatters :Array = [];
|
||||||
//
|
|
||||||
// /** Observers that are watching our chatters list. */
|
/** Observers that are watching our chatters list. */
|
||||||
// protected ObserverList _chatterObservers =
|
protected var _chatterObservers :ObserverList = new ObserverList();
|
||||||
// new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
|
|
||||||
|
|
||||||
/** Registered chat command handlers. */
|
/** Registered chat command handlers. */
|
||||||
protected static const _handlers :HashMap = new HashMap();
|
protected static const _handlers :HashMap = new HashMap();
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// $Id: ChatFilter.java 4191 2006-06-13 22:42:20Z ray $
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.crowd.chat.client {
|
||||||
|
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters messages chat messages to or from the server.
|
||||||
|
*/
|
||||||
|
public interface ChatFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Filter a chat message.
|
||||||
|
* @param msg the message text to be filtered.
|
||||||
|
* @param otherUser an optional argument that represents the target or the
|
||||||
|
* speaker, depending on 'outgoing', and can be considered in filtering if
|
||||||
|
* it is provided.
|
||||||
|
* @param outgoing true if the message is going out to the server.
|
||||||
|
*
|
||||||
|
* @return the filtered message, or null to block it completely.
|
||||||
|
*/
|
||||||
|
function filter (msg :String, otherUser :Name, outgoing :Boolean) :String;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
package com.threerings.crowd.chat.client {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface to receive information about the most recent users
|
||||||
|
* that we've been chatting with.
|
||||||
|
*/
|
||||||
|
public interface ChatterObserver
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called when the list of chatters has been changed.
|
||||||
|
*/
|
||||||
|
function chattersUpdated (chatterNames :Array) :void;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
package com.threerings.crowd.chat.client {
|
||||||
|
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface used with the ChatDirector to validate which usernames
|
||||||
|
* may be added to the chatter list.
|
||||||
|
*/
|
||||||
|
public interface ChatterValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Arbitrates whether the username may be added to the chatters list.
|
||||||
|
*/
|
||||||
|
function isChatterValid (username :Name) :Boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user