Search in sources :

Example 1 with NodeResult

use of com.roof.chain.support.NodeResult 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 NodeResult

use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.

the class MessageHandlerNode method doNode.

public NodeResult doNode(MessageRequest request, Message message, ValueStack valueStack) {
    String receiver = request.getReceiver();
    if (!userService.exist(receiver)) {
        return new NodeResult(RECEIVER_NOT_EXISTS);
    }
    List<UserState> states = userStateService.getStates(receiver);
    if (states == null || states.size() == 0) {
        NodeResult r = new NodeResult(RECEIVER_OFFLINE);
        r.setData(message);
        return r;
    }
    valueStack.set(ImConstant.USER_STATES, states);
    return new NodeResult(MESSAGE_HANDLE_SUCCESS);
}
Also used : UserState(org.roof.im.user.UserState) NodeResult(com.roof.chain.support.NodeResult)

Example 3 with NodeResult

use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.

the class BatchSetMessageReceivedNode method doNode.

public NodeResult doNode(ValueStack valueStack) {
    NodeResult result = valueStack.getPreResult();
    if (result == null) {
        return new NodeResult(MESSAGE_IS_NULL);
    }
    Object r = result.getData();
    if (r == null) {
        return new NodeResult(CHANGE_MESSAGE_STATE_SUCCESS);
    }
    if (r instanceof List) {
        List<Message> messages = (List) r;
        if (messages.size() == 0) {
            return new NodeResult(CHANGE_MESSAGE_STATE_SUCCESS);
        }
        long[] ids = new long[messages.size()];
        for (int i = 0; i < messages.size(); i++) {
            Message message = messages.get(i);
            ids[i] = message.getId();
        }
        try {
            messageDao.updateStateBatch(ids, 1);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            return new NodeResult(CHANGE_MESSAGE_STATE_ERROR);
        }
        NodeResult nr = new NodeResult(CHANGE_MESSAGE_STATE_SUCCESS);
        nr.setData(r);
        return nr;
    }
    return new NodeResult(MESSAGE_IS_NULL);
}
Also used : Message(org.roof.im.message.Message) NodeResult(com.roof.chain.support.NodeResult) List(java.util.List)

Example 4 with NodeResult

use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.

the class RequestMessagePublishNode method doNode.

public NodeResult doNode(Message message, List<UserState> userStates, ValueStack valueStack) {
    for (UserState userState : userStates) {
        boolean result = false;
        try {
            Message c = new Message();
            BeanUtils.copyProperties(message, c);
            c.setClientType(userState.getClientType());
            result = messagePublisher.publish(c, userState.getServerName(), timeout, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        if (!result) {
            LOGGER.error("push message error: {} ,{}", userState.getUsername(), JSONObject.toJSONString(message));
        }
    }
    NodeResult result = new NodeResult(PUBLISH_SUCCESS);
    result.setData(message);
    return result;
}
Also used : UserState(org.roof.im.user.UserState) Message(org.roof.im.message.Message) NodeResult(com.roof.chain.support.NodeResult)

Example 5 with NodeResult

use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.

the class ReturnMessageExchangeNode method doNode.

public NodeResult doNode(ValueStack valueStack) {
    NodeResult result = valueStack.getPreResult();
    result.setNext(returnMessage);
    return result;
}
Also used : NodeResult(com.roof.chain.support.NodeResult)

Aggregations

NodeResult (com.roof.chain.support.NodeResult)9 UserState (org.roof.im.user.UserState)4 List (java.util.List)2 Message (org.roof.im.message.Message)2 Session (org.roof.im.session.Session)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Sts (com.qcloud.Module.Sts)1 QcloudApiModuleCenter (com.qcloud.QcloudApiModuleCenter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 SessionVo (org.roof.im.chain.handler.SessionVo)1 Response (org.roof.im.response.Response)1