use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient in project muikku by otavanopisto.
the class CommunicatorRESTService method markInboxAsRead.
@POST
@Path("/items/{COMMUNICATORMESSAGEID}/markasread")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response markInboxAsRead(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessageRecipient> list = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, messageId, false);
for (CommunicatorMessageRecipient r : list) {
communicatorController.updateRead(r, true);
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient in project muikku by otavanopisto.
the class CommunicatorRESTService method getReceivedItemsCount.
@GET
@Path("/receiveditemscount")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getReceivedItemsCount() {
UserEntity user = sessionController.getLoggedUserEntity();
List<CommunicatorMessageRecipient> receivedItems = communicatorController.listReceivedItemsByUserAndRead(user, false, false);
// TODO could be more elegant, i presume
long count = 0;
Set<Long> ids = new HashSet<Long>();
for (CommunicatorMessageRecipient r : receivedItems) {
Long id = r.getCommunicatorMessage().getCommunicatorMessageId().getId();
if (!ids.contains(id)) {
ids.add(id);
count++;
}
}
return Response.ok(count).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient in project muikku by otavanopisto.
the class CommunicatorTrashRESTService method listUserTrashItems.
@GET
@Path("/trash")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserTrashItems(@QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
UserEntity user = sessionController.getLoggedUserEntity();
List<CommunicatorMessage> trashItems = communicatorController.listTrashItems(user, firstResult, maxResults);
List<CommunicatorThreadRESTModel> result = new ArrayList<CommunicatorThreadRESTModel>();
for (CommunicatorMessage receivedItem : trashItems) {
String categoryName = receivedItem.getCategory() != null ? receivedItem.getCategory().getName() : null;
boolean hasUnreadMsgs = false;
Date latestMessageDate = receivedItem.getCreated();
List<CommunicatorMessageRecipient> recipients = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, receivedItem.getCommunicatorMessageId(), true);
for (CommunicatorMessageRecipient recipient : recipients) {
hasUnreadMsgs = hasUnreadMsgs || Boolean.FALSE.equals(recipient.getReadByReceiver());
Date created = recipient.getCommunicatorMessage().getCreated();
latestMessageDate = latestMessageDate == null || latestMessageDate.before(created) ? created : latestMessageDate;
}
UserBasicInfo senderBasicInfo = restModels.getSenderBasicInfo(receivedItem);
Long messageCountInThread = communicatorController.countMessagesByUserAndMessageId(user, receivedItem.getCommunicatorMessageId(), true);
List<CommunicatorMessageRecipient> messageRecipients = communicatorController.listCommunicatorMessageRecipients(receivedItem);
List<CommunicatorMessageRecipientUserGroup> userGroupRecipients = communicatorController.listCommunicatorMessageUserGroupRecipients(receivedItem);
List<CommunicatorMessageRecipientWorkspaceGroup> workspaceGroupRecipients = communicatorController.listCommunicatorMessageWorkspaceGroupRecipients(receivedItem);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, receivedItem.getCommunicatorMessageId());
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
List<CommunicatorMessageRecipientRESTModel> restRecipients = restModels.restRecipient(messageRecipients);
List<fi.otavanopisto.muikku.rest.model.UserGroup> restUserGroupRecipients = restModels.restUserGroupRecipients(userGroupRecipients);
List<CommunicatorMessageRecipientWorkspaceGroupRESTModel> restWorkspaceRecipients = restModels.restWorkspaceGroupRecipients(workspaceGroupRecipients);
Long recipientCount = (long) messageRecipients.size() + userGroupRecipients.size() + workspaceGroupRecipients.size();
result.add(new CommunicatorSentThreadRESTModel(receivedItem.getId(), receivedItem.getCommunicatorMessageId().getId(), receivedItem.getSender(), senderBasicInfo, categoryName, receivedItem.getCaption(), receivedItem.getCreated(), restModels.tagIdsToStr(receivedItem.getTags()), hasUnreadMsgs, latestMessageDate, messageCountInThread, restLabels, restRecipients, restUserGroupRecipients, restWorkspaceRecipients, recipientCount));
}
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient in project muikku by otavanopisto.
the class CommunicatorController method trashAllThreadMessages.
public void trashAllThreadMessages(UserEntity user, CommunicatorMessageId messageId) {
List<CommunicatorMessageRecipient> received = communicatorMessageRecipientDAO.listByUserAndMessageId(user, messageId, false, false);
for (CommunicatorMessageRecipient recipient : received) {
communicatorMessageRecipientDAO.updateTrashedByReceiver(recipient, true);
}
List<CommunicatorMessage> sentMessages = communicatorMessageDAO.listMessagesInSentThread(user, messageId, false, false);
for (CommunicatorMessage message : sentMessages) {
communicatorMessageDAO.updateTrashedBySender(message, true);
}
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient in project muikku by otavanopisto.
the class CommunicatorMessageDAO method countMessagesByUserAndMessageId.
/**
* Returns the number of messages the user can see in a thread in either inbox/sent or in trash
* depending on the value of trashed parameter.
*
* @param user
* @param communicatorMessageId
* @param trashed
* @return
*/
public Long countMessagesByUserAndMessageId(UserEntity user, CommunicatorMessageId communicatorMessageId, boolean trashed) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
Join<CommunicatorMessageRecipient, CommunicatorMessage> msgJoin = root.join(CommunicatorMessageRecipient_.communicatorMessage);
criteria.select(criteriaBuilder.countDistinct(msgJoin));
criteria.where(criteriaBuilder.or(criteriaBuilder.and(criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), user.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), trashed), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE)), criteriaBuilder.and(criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.sender), user.getId()), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.trashedBySender), trashed), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.archivedBySender), Boolean.FALSE))));
return entityManager.createQuery(criteria).getSingleResult();
}
Aggregations