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