Search in sources :

Example 6 with UserState

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;
}
Also used : UserState(org.roof.im.user.UserState) NodeResult(com.roof.chain.support.NodeResult)

Example 7 with UserState

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;
}
Also used : UserState(org.roof.im.user.UserState) ArrayList(java.util.ArrayList)

Example 8 with UserState

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;
}
Also used : UserState(org.roof.im.user.UserState)

Aggregations

UserState (org.roof.im.user.UserState)8 NodeResult (com.roof.chain.support.NodeResult)4 ArrayList (java.util.ArrayList)3 ValueStack (com.roof.chain.api.ValueStack)1 GenericValueStack (com.roof.chain.support.GenericValueStack)1 List (java.util.List)1 Test (org.junit.Test)1 SessionVo (org.roof.im.chain.handler.SessionVo)1 Message (org.roof.im.message.Message)1 OfflineRequest (org.roof.im.request.OfflineRequest)1 Session (org.roof.im.session.Session)1