2020-02-10 22:29:34 +01:00
|
|
|
package envoy.server.processors;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2020-04-02 16:32:23 +02:00
|
|
|
import envoy.data.Contact;
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.event.contact.*;
|
2020-10-19 18:17:51 +02:00
|
|
|
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.server.data.*;
|
|
|
|
import envoy.server.net.*;
|
2020-02-10 22:29:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @author Maximilian Käfer
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-08-22 13:37:07 +02:00
|
|
|
public final class UserSearchProcessor implements ObjectProcessor<UserSearchRequest> {
|
2020-02-10 22:29:34 +01:00
|
|
|
|
|
|
|
/**
|
2020-10-19 18:17:51 +02:00
|
|
|
* 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.
|
2020-02-10 22:29:34 +01:00
|
|
|
*
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
|
|
|
@Override
|
2020-10-19 18:17:51 +02:00
|
|
|
public void process(UserSearchRequest request, long socketID, ObjectWriteProxy writeProxy)
|
|
|
|
throws IOException {
|
2020-03-26 20:14:09 +01:00
|
|
|
writeProxy.write(socketID,
|
2020-10-19 18:17:51 +02:00
|
|
|
new UserSearchResult(PersistenceManager.getInstance()
|
|
|
|
.searchUsers(request.get(),
|
|
|
|
ConnectionManager.getInstance().getUserIDBySocketID(socketID))
|
|
|
|
.stream()
|
|
|
|
.map(User::toCommon)
|
|
|
|
.collect(Collectors.toList())));
|
2020-02-10 22:29:34 +01:00
|
|
|
}
|
|
|
|
}
|