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.*;
|
|
|
|
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-04-02 16:32:23 +02:00
|
|
|
* Writes a list of contacts to the client containing all {@link Contact}s
|
2020-02-10 22:29:34 +01:00
|
|
|
* 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
|
2020-07-13 19:02:40 +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-07-13 19:02:40 +02:00
|
|
|
new UserSearchResult(PersistenceManager.getInstance()
|
2020-07-06 11:40:13 +02:00
|
|
|
.searchUsers(request.get(), ConnectionManager.getInstance().getUserIDBySocketID(socketID))
|
2020-02-10 22:29:34 +01:00
|
|
|
.stream()
|
2020-03-25 16:34:55 +01:00
|
|
|
.map(User::toCommon)
|
2020-02-10 22:29:34 +01:00
|
|
|
.collect(Collectors.toList())));
|
|
|
|
}
|
|
|
|
}
|