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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations