use of com.google.gerrit.server.mail.send.ModifyReviewerSender in project gerrit by GerritCodeReview.
the class ModifyReviewersEmail method emailReviewersAsync.
public void emailReviewersAsync(IdentifiedUser user, Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Account.Id> removed, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, Collection<Address> removedByEmail, NotifyResolver.Result notify) {
// The user knows they added/removed themselves, don't bother emailing them.
Account.Id userId = user.getAccountId();
ImmutableList<Account.Id> immutableToMail = added.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToCopy = copied.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToRemove = removed.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
if (immutableToMail.isEmpty() && immutableToCopy.isEmpty() && immutableToRemove.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty() && removedByEmail.isEmpty()) {
return;
}
// Make immutable copies of collections and hand over only immutable data types to the other
// thread.
Change.Id cId = change.getId();
Project.NameKey projectNameKey = change.getProject();
ImmutableList<Address> immutableAddedByEmail = ImmutableList.copyOf(addedByEmail);
ImmutableList<Address> immutableCopiedByEmail = ImmutableList.copyOf(copiedByEmail);
ImmutableList<Address> immutableRemovedByEmail = ImmutableList.copyOf(removedByEmail);
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailsExecutor.submit(() -> {
try {
ModifyReviewerSender emailSender = addReviewerSenderFactory.create(projectNameKey, cId);
emailSender.setNotify(notify);
emailSender.setFrom(userId);
emailSender.addReviewers(immutableToMail);
emailSender.addReviewersByEmail(immutableAddedByEmail);
emailSender.addExtraCC(immutableToCopy);
emailSender.addExtraCCByEmail(immutableCopiedByEmail);
emailSender.addRemovedReviewers(immutableToRemove);
emailSender.addRemovedByEmailReviewers(immutableRemovedByEmail);
emailSender.setMessageId(messageIdGenerator.fromChangeUpdate(change.getProject(), change.currentPatchSetId()));
emailSender.send();
} catch (Exception err) {
logger.atSevere().withCause(err).log("Cannot send email to new reviewers of change %s", change.getId());
}
});
}
Aggregations