Search in sources :

Example 1 with SessionVo

use of org.roof.im.chain.handler.SessionVo in project roof-im by madfroglx.

the class CreateSessionVoNode method doNode.

public NodeResult<List<SessionVo>> doNode(Request request, List<Session> sessions) {
    // TODO session缓存
    if (sessions == null || sessions.size() == 0) {
        return new NodeResult<>(NO_INCOMPLETE_SESSION);
    }
    List<SessionVo> sessionVos = new ArrayList<>();
    String username = request.getUsername();
    for (Session session : sessions) {
        String receiver;
        if (StringUtils.equals(session.getReceiver(), username)) {
            receiver = session.getSender();
        } else {
            receiver = session.getReceiver();
        }
        String userState = ImConstant.OFFLINE;
        List<UserState> userStates = userStateService.getStates(receiver);
        if (userStates != null) {
            for (UserState state : userStates) {
                if (StringUtils.equals(state.getState(), ImConstant.ONLINE)) {
                    userState = ImConstant.ONLINE;
                }
            }
        }
        SessionVo sessionVo = new SessionVo();
        sessionVo.setSessionId(session.getId());
        sessionVo.setReceiver(receiver);
        sessionVo.setStartTime(session.getStartTime());
        sessionVo.setEndTime(session.getEndTime());
        sessionVo.setRealEndTime(session.getRealEndTime());
        sessionVo.setState(session.getState());
        sessionVo.setUserState(userState);
        sessionVos.add(sessionVo);
    }
    NodeResult<List<SessionVo>> result = new NodeResult<>(QUERY_INCOMPLETE_SESSION_SUCCESS);
    result.setData(sessionVos);
    return result;
}
Also used : SessionVo(org.roof.im.chain.handler.SessionVo) UserState(org.roof.im.user.UserState) NodeResult(com.roof.chain.support.NodeResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Session(org.roof.im.session.Session)

Aggregations

NodeResult (com.roof.chain.support.NodeResult)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SessionVo (org.roof.im.chain.handler.SessionVo)1 Session (org.roof.im.session.Session)1 UserState (org.roof.im.user.UserState)1