Search in sources :

Example 1 with Session

use of org.roof.im.session.Session 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)

Example 2 with Session

use of org.roof.im.session.Session in project roof-im by madfroglx.

the class SessionVerifyNode method doNode.

public String doNode(MessageRequest request, ValueStack valueStack) {
    String username = request.getUsername();
    String receiver = request.getReceiver();
    // TODO 增加session双方字段
    Session effective = sessionManager.queryEffective(username, receiver);
    if (effective == null) {
        effective = sessionManager.queryEffective(receiver, username);
    }
    if (effective == null) {
        return SESSION_NOT_EXIST;
    }
    valueStack.set(ImConstant.EFFECTIVE_SESSION, effective);
    return SESSION_EXIST;
}
Also used : Session(org.roof.im.session.Session)

Example 3 with Session

use of org.roof.im.session.Session in project roof-im by madfroglx.

the class StartSessionHandlerNode method doNode.

public String doNode(StartSessionRequest request, ValueStack valueStack) {
    Long sessionId = request.getSessionId();
    Long startTime = request.getStartTime();
    Long endTime = request.getEndTime();
    Session session = sessionDao.load(sessionId);
    if (session == null) {
        return SESSION_NOT_EXISTS;
    }
    if (session.getState() == 2) {
        return SESSION_IS_CLOSED;
    }
    if (session.getStartTime() == 0) {
        session.setStartTime(startTime);
    }
    if (session.getEndTime() == 0) {
        session.setEndTime(endTime);
    }
    if (session.getStartTime() > session.getEndTime()) {
        return START_TIME_GT_END_TIME;
    }
    return SESSION_START_SUCCESS;
}
Also used : Session(org.roof.im.session.Session)

Example 4 with Session

use of org.roof.im.session.Session in project roof-im by madfroglx.

the class CloseSessionTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    Session session = sessionManager.open("abc", "efg", 0, 99);
    CloseSessionRequest request = new CloseSessionRequest();
    request.setSessionId(session.getId());
    request.setRequestType(RequestType.closeSession.name());
    request.setToken("abc");
    ValueStack valueStack = getValueStack(request);
    enterChain.doChain(valueStack);
}
Also used : ValueStack(com.roof.chain.api.ValueStack) GenericValueStack(com.roof.chain.support.GenericValueStack) CloseSessionRequest(org.roof.im.request.CloseSessionRequest) Session(org.roof.im.session.Session) Test(org.junit.Test)

Example 5 with Session

use of org.roof.im.session.Session in project roof-im by madfroglx.

the class OpenSessionHandlerNode method doNode.

@Override
public NodeResult<Session> doNode(OpenSessionRequest request, ValueStack valueStack) {
    String sender = request.getSender();
    String receiver = request.getReceiver();
    if (!userService.exist(sender)) {
        return new NodeResult<>(SENDER_NOT_EXIST);
    }
    if (!userService.exist(receiver)) {
        return new NodeResult<>(RECEIVER_NOT_EXIST);
    }
    // 双方已存在session
    Session sessionExist = sessionManager.queryEffective(sender, receiver);
    if (sessionExist != null) {
        NodeResult<Session> nodeResult = new NodeResult<>(SESSION_ALREADY_EXIST);
        nodeResult.setData(sessionExist);
        return nodeResult;
    }
    Session session = sessionManager.open(sender, receiver, request.getStartTime(), request.getEndTime());
    NodeResult<Session> nodeResult = new NodeResult<>(OPEN_SESSION_SUCCESS);
    nodeResult.setData(session);
    return nodeResult;
}
Also used : NodeResult(com.roof.chain.support.NodeResult) Session(org.roof.im.session.Session)

Aggregations

Session (org.roof.im.session.Session)6 NodeResult (com.roof.chain.support.NodeResult)2 ValueStack (com.roof.chain.api.ValueStack)1 GenericValueStack (com.roof.chain.support.GenericValueStack)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 SessionVo (org.roof.im.chain.handler.SessionVo)1 CloseSessionRequest (org.roof.im.request.CloseSessionRequest)1 UserState (org.roof.im.user.UserState)1