use of com.axelor.mail.db.repo.MailFollowerRepository in project axelor-open-suite by axelor.
the class MailServiceBaseImpl method recipients.
@Override
protected Set<String> recipients(MailMessage message, Model entity) {
final Set<String> recipients = new LinkedHashSet<>();
final MailFollowerRepository followers = Beans.get(MailFollowerRepository.class);
String entityName = entity.getClass().getName();
if (message.getRecipients() != null) {
for (MailAddress address : message.getRecipients()) {
recipients.add(address.getAddress());
}
}
for (MailFollower follower : followers.findAll(message)) {
if (follower.getArchived()) {
continue;
}
User user = follower.getUser();
if (user != null) {
if (!(user.getReceiveEmails() && user.getFollowedMetaModelSet().stream().anyMatch(x -> x.getFullName().equals(entityName)))) {
continue;
} else {
Partner partner = user.getPartner();
if (partner != null && partner.getEmailAddress() != null) {
recipients.add(partner.getEmailAddress().getAddress());
} else if (user.getEmail() != null) {
recipients.add(user.getEmail());
}
}
} else {
if (follower.getEmail() != null) {
recipients.add(follower.getEmail().getAddress());
} else {
log.info("No email address found for follower : " + follower);
}
}
}
return Sets.filter(recipients, Predicates.notNull());
}
use of com.axelor.mail.db.repo.MailFollowerRepository in project axelor-open-suite by axelor.
the class MailingListMessageBaseRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
if (json != null && json.get("id") != null) {
final MailingListMessage entity = find((Long) json.get("id"));
final MailFollowerRepository followers = Beans.get(MailFollowerRepository.class);
final MailFollower follower = followers.findOne(entity, AuthUtils.getUser());
json.put("_following", follower != null && follower.getArchived() == Boolean.FALSE);
json.put("_image", entity.getImage() != null);
}
return json;
}
use of com.axelor.mail.db.repo.MailFollowerRepository in project axelor-open-suite by axelor.
the class EventServiceImpl method manageFollowers.
@Override
@Transactional
public void manageFollowers(Event event) {
MailFollowerRepository mailFollowerRepo = Beans.get(MailFollowerRepository.class);
List<MailFollower> followers = mailFollowerRepo.findAll(event);
List<ICalendarUser> attendeesSet = event.getAttendees();
if (followers != null)
followers.forEach(x -> mailFollowerRepo.remove(x));
mailFollowerRepo.follow(event, event.getUser());
if (attendeesSet != null) {
for (ICalendarUser user : attendeesSet) {
if (user.getUser() != null) {
mailFollowerRepo.follow(event, user.getUser());
} else {
MailAddress mailAddress = Beans.get(MailAddressRepository.class).findOrCreate(user.getEmail(), user.getName());
mailFollowerRepo.follow(event, mailAddress);
}
}
}
}
Aggregations