Search in sources :

Example 1 with UserMessage

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;
    });
}
Also used : UserMessage(org.hisp.dhis.message.UserMessage)

Example 2 with UserMessage

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);
}
Also used : CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UserMessage(org.hisp.dhis.message.UserMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 3 with UserMessage

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;
}
Also used : User(org.hisp.dhis.user.User) MessageConversation(org.hisp.dhis.message.MessageConversation) UserMessage(org.hisp.dhis.message.UserMessage)

Aggregations

UserMessage (org.hisp.dhis.message.UserMessage)3 User (org.hisp.dhis.user.User)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 MessageConversation (org.hisp.dhis.message.MessageConversation)1 CurrentUser (org.hisp.dhis.user.CurrentUser)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1