use of org.roof.im.user.UserState 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 org.roof.im.user.UserState 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 org.roof.im.user.UserState in project roof-im by madfroglx.
the class OfflineHandlerNode method doNode.
@Override
public String doNode(OfflineRequest request, ValueStack valueStack) {
String username = request.getUsername();
String serverName = serverNameBuilder.getName();
List<UserState> userStates = userStateService.getStates(username);
if (userStates == null || userStates.size() == 0) {
return USER_NOT_ONLINE;
}
for (Iterator<UserState> iterator = userStates.iterator(); iterator.hasNext(); ) {
UserState next = iterator.next();
if (StringUtils.equals(next.getServerName(), serverName)) {
iterator.remove();
if (userStates.size() == 0) {
userStateService.offline(username);
} else {
userStateService.online(username, userStates);
}
return OFFLINE_SUCCESS;
}
}
return USER_NOT_ONLINE;
}
use of org.roof.im.user.UserState in project roof-im by madfroglx.
the class OfflineTest method testSuccess.
@Test
public void testSuccess() throws Exception {
List<UserState> states = new ArrayList<>();
UserState userState = new UserState();
userState.setConnectId("1");
userState.setClientType(ClientType.h5.name());
userState.setUsername("abc");
userState.setServerName(serverNameBuilder.getName());
states.add(userState);
UserState userState2 = new UserState();
userState2.setConnectId("1");
userState2.setClientType("applet");
userState2.setUsername("abc");
userState2.setServerName(serverNameBuilder.getName());
states.add(userState2);
userStateService.online("abc", states);
OfflineRequest offlineRequest = createRequest();
ValueStack valueStack = createValueStack(offlineRequest);
enterChain.doChain(valueStack);
}
use of org.roof.im.user.UserState 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;
}
Aggregations