use of org.roof.im.user.UserState in project roof-im by madfroglx.
the class MessageRequestHandlerNode method doNode.
public NodeResult<Message> doNode(Message message, ValueStack valueStack) {
// MessageRequest messageRequest;
// if (request instanceof MessageRequest) {
// messageRequest = (MessageRequest) request;
// } else {
// LOGGER.error("request error type : {}, mast be {}",
// request.getClass().getSimpleName(), MessageRequest.class.getSimpleName());
// return new NodeResult<>(NONSUPPORT_REQUEST_TYPE);
// }
String receiver = message.getReceiver();
List<UserState> userStates = userStateService.getStates(receiver);
String connectId = null;
for (UserState userState : userStates) {
if (StringUtils.equals(userState.getServerName(), serverNameBuilder.getName()) && StringUtils.equals(userState.getClientType(), message.getClientType())) {
connectId = userState.getConnectId();
}
}
if (connectId == null) {
return new NodeResult(CANNOT_FOUND_CONNECT);
}
valueStack.set(ImConstant.CONNECT_ID, connectId);
NodeResult result = new NodeResult(MESSAGE_REQUEST_TRANSFORM_SUCCESS);
result.setData(message);
valueStack.set(ImConstant.REQUEST_TYPE, ImConstant.MESSAGE);
return result;
}
use of org.roof.im.user.UserState in project roof-im by madfroglx.
the class UserStateHandlerNode method doNode.
public String doNode(UserStateRequest request, ValueStack valueStack) {
String username = request.getUsername();
List<UserState> userStates = userStateService.getStates(username);
List<UserState> newUserStates = new ArrayList<>();
UserState userState = createUserState(request);
newUserStates.add(userState);
if (userStates != null && userStates.size() > 0) {
for (UserState us : userStates) {
if (!StringUtils.equals(userState.getClientType(), us.getClientType())) {
newUserStates.add(us);
}
}
}
userStateService.online(username, newUserStates);
return USER_STATE_CHANGE_SUCCESS;
}
use of org.roof.im.user.UserState in project roof-im by madfroglx.
the class UserStateHandlerNode method createUserState.
private UserState createUserState(UserStateRequest userStateRequest) {
String nodeName = serverNameBuilder.getName();
UserState userState = new UserState();
userState.setUsername(userStateRequest.getUsername());
userState.setConnectId(userStateRequest.getConnectId());
userState.setClientType(userStateRequest.getClientType());
userState.setServerName(nodeName);
userState.setUpdateTime(System.currentTimeMillis());
userState.setState(userStateRequest.getRequestType());
return userState;
}
Aggregations