/** * Sends notification to user about received private message. * * @param recipient a person to be notified about received private message by email * @param pm private message itself */ public void sendReceivedPrivateMessageNotification(JCUser recipient, PrivateMessage pm) { try { String urlSuffix = "/pm/inbox/" + pm.getId(); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put("recipient", recipient); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(recipient.getEmail(), messageSource.getMessage("receivedPrivateMessageNotification.subject", new Object[]{}, locale), model, "receivedPrivateMessageNotification.vm"); } catch (MailingFailedException e) { LOGGER.error(String.format(LOG_TEMPLATE, "Private message", pm.getId(), recipient.getUsername())); } }
/** * Create the full private message dto from {@link PrivateMessage} * * @param pm private message for conversion * @return dto for full private message */ public static PrivateMessageDto getFullPmDtoFor(PrivateMessage pm) { PrivateMessageDto dto = new PrivateMessageDto(); dto.setBody(pm.getBody()); dto.setTitle(pm.getTitle()); if (pm.getUserTo() != null) { dto.setRecipient(pm.getUserTo().getUsername()); } dto.setId(pm.getId()); return dto; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendMessage(String title, String body, JCUser recipient, JCUser userFrom) { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendDraft(long id, String title, String body, JCUser recipient, JCUser userFrom) throws NotFoundException { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setId(id); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.deleteFromAcl(pm); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message(was draft) to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public void saveDraft(long id, JCUser userTo, String title, String body, JCUser userFrom) { PrivateMessage pm; if (this.getDao().isExist(id)) { pm = this.getDao().get(id); pm.setUserTo(userTo); pm.setTitle(title); pm.setBody(body); } else { pm = new PrivateMessage(userTo, userFrom, title, body); pm.setStatus(PrivateMessageStatus.DRAFT); } this.getDao().saveOrUpdate(pm); JCUser user = userService.getCurrentUser(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(user).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(user).on(pm).flush(); logger.debug("Updated private message draft. Message id={}", pm.getId()); }