This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/server/src/main/java/envoy/server/processors/UserSearchProcessor.java

38 lines
1.0 KiB
Java
Executable File

package envoy.server.processors;
import java.io.IOException;
import java.util.stream.Collectors;
import envoy.data.Contact;
import envoy.event.contact.*;
import envoy.server.data.*;
import envoy.server.net.*;
/**
* @author Kai S. K. Engelbart
* @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-alpha
*/
public final class UserSearchProcessor implements ObjectProcessor<UserSearchRequest> {
/**
* Writes a list of contacts to the client containing all {@link Contact}s matching the search
* phrase contained inside the request. The client and their contacts are excluded from the
* result.
*
* @since Envoy Server Standalone v0.1-alpha
*/
@Override
public void process(UserSearchRequest request, long socketID, ObjectWriteProxy writeProxy)
throws IOException {
writeProxy.write(socketID,
new UserSearchResult(PersistenceManager.getInstance()
.searchUsers(request.get(),
ConnectionManager.getInstance().getUserIDBySocketID(socketID))
.stream()
.map(User::toCommon)
.collect(Collectors.toList())));
}
}