Allow an optional ResultListener to be passed into requestTell that will

tell us whether or not the tell succeeded.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2632 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2003-06-03 23:36:18 +00:00
parent 40afe3cb94
commit d3f3995cb7
2 changed files with 25 additions and 11 deletions
@@ -1,5 +1,5 @@
// //
// $Id: ChatDirector.java,v 1.44 2003/06/03 21:41:33 ray Exp $ // $Id: ChatDirector.java,v 1.45 2003/06/03 23:36:18 ray Exp $
package com.threerings.crowd.chat.client; package com.threerings.crowd.chat.client;
@@ -8,6 +8,7 @@ import java.util.LinkedList;
import com.samskivert.util.HashIntMap; import com.samskivert.util.HashIntMap;
import com.samskivert.util.ObserverList; import com.samskivert.util.ObserverList;
import com.samskivert.util.ResultListener;
import com.threerings.presents.client.BasicDirector; import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
@@ -346,38 +347,51 @@ public class ChatDirector extends BasicDirector
* @param target the username of the user to which the tell message * @param target the username of the user to which the tell message
* should be delivered. * should be delivered.
* @param message the contents of the tell message. * @param message the contents of the tell message.
* @param rl an optional result listener if you'd like to be notified
* of success or failure.
*/ */
public void requestTell (final String target, final String message) public void requestTell (
final String target, final String message, final ResultListener rl)
{ {
// make sure they can say what they want to say // make sure they can say what they want to say
_validateMessageOp.setMessage(target, message); _validateMessageOp.setMessage(target, message);
_validators.apply(_validateMessageOp); _validators.apply(_validateMessageOp);
if (!_validateMessageOp.isValid()) { if (!_validateMessageOp.isValid()) {
if (rl != null) {
rl.requestFailed(null);
}
return; return;
} }
// create a listener that will report success or failure // create a listener that will report success or failure
ChatService.TellListener listener = new ChatService.TellListener() { ChatService.TellListener listener = new ChatService.TellListener() {
public void tellSucceeded () { public void tellSucceeded () {
dispatchMessage(new TellFeedbackMessage( success(xlate(_bundle, MessageBundle.tcompose(
xlate(_bundle, MessageBundle.tcompose( "m.told_format", target, message)));
"m.told_format", target, message))));
addChatter(target);
} }
public void tellSucceededIdle (long idletime) { public void tellSucceededIdle (long idletime) {
dispatchMessage(new TellFeedbackMessage( success(xlate(_bundle, MessageBundle.compose(
xlate(_bundle, MessageBundle.compose(
"m.told_idle_format", MessageBundle.taint(target), "m.told_idle_format", MessageBundle.taint(target),
MessageBundle.taint(message), MessageBundle.taint(message),
TimeUtil.getTimeOrderString(idletime, TimeUtil.MINUTE))))); TimeUtil.getTimeOrderString(idletime, TimeUtil.MINUTE))));
}
protected void success (String feedback) {
dispatchMessage(new TellFeedbackMessage(feedback));
addChatter(target); addChatter(target);
if (rl != null) {
rl.requestCompleted(target);
}
} }
public void requestFailed (String reason) { public void requestFailed (String reason) {
String msg = MessageBundle.compose( String msg = MessageBundle.compose(
"m.tell_failed", MessageBundle.taint(target), reason); "m.tell_failed", MessageBundle.taint(target), reason);
displayFeedbackMessage(_bundle, msg); displayFeedbackMessage(_bundle, msg);
if (rl != null) {
rl.requestFailed(null);
}
} }
}; };
@@ -1,5 +1,5 @@
// //
// $Id: ChatPanel.java,v 1.23 2003/06/03 21:41:33 ray Exp $ // $Id: ChatPanel.java,v 1.24 2003/06/03 23:36:18 ray Exp $
package com.threerings.micasa.client; package com.threerings.micasa.client;
@@ -206,7 +206,7 @@ public class ChatPanel
String message = text.substring(uidx + username.length()).trim(); String message = text.substring(uidx + username.length()).trim();
// request to send this text as a tell message // request to send this text as a tell message
_chatdtr.requestTell(username, message); _chatdtr.requestTell(username, message, null);
} else if (text.startsWith("/clear")) { } else if (text.startsWith("/clear")) {
// clear the chat box // clear the chat box