use of org.roof.im.message.Message in project roof-im by madfroglx.
the class SaveMessageNode method doNode.
// TODO 保存sessionId
public String doNode(MessageRequest request, Session effectiveSession, ValueStack valueStack) {
if (request == null) {
return MESSAGE_IS_NULL;
}
String receiver = request.getReceiver();
String username = request.getUsername();
Message message = new Message();
message.setPayload(request.getPayload());
message.setReceiver(receiver);
message.setSender(username);
message.setCreateTime(request.getCreateTime());
message.setType(request.getType().name());
message.setMessageKey(UserService.joinUsername(receiver, username));
message.setSessionId(effectiveSession == null ? null : effectiveSession.getId());
messageDao.save(message);
valueStack.set(ImConstant.MESSAGE, message);
return MESSAGE_SAVE_SUCCESS;
}
use of org.roof.im.message.Message in project roof-im by madfroglx.
the class SetMessageReceivedNode method doNode.
public String doNode(Response response) {
if (response == null) {
return MESSAGE_IS_NULL;
}
Object result = response.getResult();
Message message = null;
if (result instanceof Message) {
message = (Message) result;
}
if (message == null) {
return MESSAGE_IS_NULL;
}
if (message.getId() == null || message.getId() == 0) {
return MESSAGE_ID_NOT_EXIST;
}
int affectedRows = messageDao.updateState(message.getId(), 1);
if (affectedRows == 0) {
return MESSAGE_ID_NOT_EXIST;
}
return CHANGE_MESSAGE_STATE_SUCCESS;
}
use of org.roof.im.message.Message 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 org.roof.im.message.Message 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