Expose the chat history between crowd peers.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5992 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2009-11-10 00:34:41 +00:00
parent 5e6cf46926
commit 90a21319f1
5 changed files with 56 additions and 0 deletions
@@ -28,6 +28,7 @@ import com.threerings.presents.client.InvocationService;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.chat.server.SpeakUtil;
/**
* Bridges certain Crowd services between peers in a cluster configuration.
@@ -45,4 +46,10 @@ public interface CrowdPeerService extends InvocationService
* Dispatches a broadcast message on this peer.
*/
void deliverBroadcast (Client client, Name from, byte levelOrMode, String bundle, String msg);
/**
* Obtains the messages that the user has heard on this peer. On success, the listener will
* receive a {@code List} of {@link SpeakUtil.ChatHistoryEntry} instances.
*/
void getChatHistory (Client caller, Name user, ResultListener lner);
}
@@ -26,6 +26,7 @@ import com.threerings.crowd.chat.data.ChatMarshaller;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.peer.client.CrowdPeerService;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.util.Name;
@@ -62,4 +63,17 @@ public class CrowdPeerMarshaller extends InvocationMarshaller
arg2, arg3, listener4
});
}
/** The method id used to dispatch {@link #getChatHistory} requests. */
public static final int GET_CHAT_HISTORY = 3;
// from interface CrowdPeerService
public void getChatHistory (Client arg1, Name arg2, InvocationService.ResultListener arg3)
{
InvocationMarshaller.ResultMarshaller listener3 = new InvocationMarshaller.ResultMarshaller();
listener3.listener = arg3;
sendRequest(arg1, GET_CHAT_HISTORY, new Object[] {
arg2, listener3
});
}
}
@@ -24,6 +24,7 @@ package com.threerings.crowd.peer.server;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.peer.data.CrowdPeerMarshaller;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
@@ -67,6 +68,12 @@ public class CrowdPeerDispatcher extends InvocationDispatcher<CrowdPeerMarshalle
);
return;
case CrowdPeerMarshaller.GET_CHAT_HISTORY:
((CrowdPeerProvider)provider).getChatHistory(
source, (Name)args[0], (InvocationService.ResultListener)args[1]
);
return;
default:
super.dispatchRequest(source, methodId, args);
return;
@@ -21,11 +21,15 @@
package com.threerings.crowd.peer.server;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import com.google.inject.internal.Lists;
import com.samskivert.util.Lifecycle;
import com.threerings.util.Name;
import com.threerings.presents.client.InvocationService.ResultListener;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.peer.data.ClientInfo;
import com.threerings.presents.peer.data.NodeObject;
@@ -38,6 +42,8 @@ import com.threerings.presents.server.PresentsSession;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.chat.server.ChatProvider;
import com.threerings.crowd.chat.server.SpeakUtil;
import com.threerings.crowd.chat.server.SpeakUtil.ChatHistoryEntry;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.peer.data.CrowdClientInfo;
import com.threerings.crowd.peer.data.CrowdNodeObject;
@@ -73,6 +79,14 @@ public abstract class CrowdPeerManager extends PeerManager
_chatprov.broadcast(from, levelOrMode, bundle, msg, false);
}
// from interface CrowdPeerProvider
public void getChatHistory (ClientObject caller, Name user, ResultListener lner)
throws InvocationException
{
lner.requestProcessed(Lists.newArrayList(Iterables.filter(
SpeakUtil.getChatHistory(user), IS_USER_MESSAGE)));
}
// from interface ChatProvider.ChatForwarder
public boolean forwardTell (UserMessage message, Name target,
ChatService.TellListener listener)
@@ -165,4 +179,11 @@ public abstract class CrowdPeerManager extends PeerManager
@Inject protected InvocationManager _invmgr;
@Inject protected ChatProvider _chatprov;
protected static final Predicate<ChatHistoryEntry> IS_USER_MESSAGE =
new Predicate<ChatHistoryEntry>() {
@Override public boolean apply (ChatHistoryEntry entry) {
return entry.message instanceof UserMessage;
}
};
}
@@ -24,6 +24,7 @@ package com.threerings.crowd.peer.server;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.peer.client.CrowdPeerService;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider;
@@ -44,4 +45,10 @@ public interface CrowdPeerProvider extends InvocationProvider
*/
void deliverTell (ClientObject caller, UserMessage arg1, Name arg2, ChatService.TellListener arg3)
throws InvocationException;
/**
* Handles a {@link CrowdPeerService#getChatHistory} request.
*/
void getChatHistory (ClientObject caller, Name arg1, InvocationService.ResultListener arg2)
throws InvocationException;
}