use of org.hisp.dhis.message.UserMessage in project dhis2-core by dhis2.
the class HibernateMessageConversationStore method getLastRecipients.
@Override
public List<UserMessage> getLastRecipients(User user, Integer first, Integer max) {
Assert.notNull(user, "User must be specified");
String sql = " select distinct userinfoid, surname, firstname from userinfo uf " + "join usermessage um on (uf.userinfoid = um.userid) " + "join messageconversation_usermessages mu on (um.usermessageid = mu.usermessageid) " + "join messageconversation mc on (mu.messageconversationid = mc.messageconversationid) " + "where mc.lastsenderid = " + user.getId();
sql += " order by userinfoid desc";
if (first != null && max != null) {
sql += " " + statementBuilder.limitRecord(first, max);
}
return jdbcTemplate.query(sql, (resultSet, count) -> {
UserMessage recipient = new UserMessage();
recipient.setId(resultSet.getInt(1));
recipient.setLastRecipientSurname(resultSet.getString(2));
recipient.setLastRecipientFirstname(resultSet.getString(3));
return recipient;
});
}
use of org.hisp.dhis.message.UserMessage in project dhis2-core by dhis2.
the class MessageConversationController method addRecipientsToMessageConversation.
@PostMapping("/{uid}/recipients")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void addRecipientsToMessageConversation(@PathVariable("uid") String uid, @RequestBody MessageConversation messageConversation) throws Exception {
org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(uid);
if (conversation == null) {
throw new WebMessageException(notFound("Message conversation does not exist: " + uid));
}
Set<User> additionalUsers = getUsersToMessageConversation(messageConversation, messageConversation.getUsers());
additionalUsers.forEach(user -> {
if (!conversation.getUsers().contains(user)) {
conversation.addUserMessage(new UserMessage(user, false));
}
});
messageService.updateMessageConversation(conversation);
}
use of org.hisp.dhis.message.UserMessage in project dhis2-core by dhis2.
the class HibernateMessageConversationStore method mapRowToMessageConversations.
private MessageConversation mapRowToMessageConversations(Object[] row) {
MessageConversation mc = (MessageConversation) row[0];
UserMessage um = (UserMessage) row[1];
User ui = (User) row[2];
User ls = (User) row[3];
mc.setRead(um.isRead());
mc.setFollowUp(um.isFollowUp());
if (ui != null) {
mc.setUserFirstname(ui.getFirstName());
mc.setUserSurname(ui.getSurname());
}
if (ls != null) {
mc.setLastSenderFirstname(ls.getFirstName());
mc.setLastSenderSurname(ls.getSurname());
}
return mc;
}
Aggregations