use of com.google.gerrit.server.mail.send.AddReviewerSender in project gerrit by GerritCodeReview.
the class PostReviewersOp method emailReviewers.
public void emailReviewers(Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify) {
if (added.isEmpty() && copied.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) {
return;
}
// Email the reviewers
//
// The user knows they added themselves, don't bother emailing them.
List<Account.Id> toMail = Lists.newArrayListWithCapacity(added.size());
Account.Id userId = user.get().getAccountId();
for (Account.Id id : added) {
if (!id.equals(userId)) {
toMail.add(id);
}
}
List<Account.Id> toCopy = Lists.newArrayListWithCapacity(copied.size());
for (Account.Id id : copied) {
if (!id.equals(userId)) {
toCopy.add(id);
}
}
if (toMail.isEmpty() && toCopy.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) {
return;
}
try {
AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId());
cm.setNotify(MoreObjects.firstNonNull(notify, NotifyHandling.ALL));
cm.setAccountsToNotify(accountsToNotify);
cm.setFrom(userId);
cm.addReviewers(toMail);
cm.addReviewersByEmail(addedByEmail);
cm.addExtraCC(toCopy);
cm.addExtraCCByEmail(copiedByEmail);
cm.send();
} catch (Exception err) {
log.error("Cannot send email to new reviewers of change " + change.getId(), err);
}
}
Aggregations