From 665d9671d1523a39c31bc8371daea1efb1de2fd1 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 17 Sep 2020 13:58:38 +0200 Subject: [PATCH] Set confirmation.welcome.account message to be quiet --- .../StandardAccountMessageService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bubble-server/src/main/java/bubble/service/account/StandardAccountMessageService.java b/bubble-server/src/main/java/bubble/service/account/StandardAccountMessageService.java index b2a0ad37..af6c98a9 100644 --- a/bubble-server/src/main/java/bubble/service/account/StandardAccountMessageService.java +++ b/bubble-server/src/main/java/bubble/service/account/StandardAccountMessageService.java @@ -18,6 +18,7 @@ import bubble.model.account.message.handlers.*; import bubble.model.cloud.CloudService; import bubble.server.BubbleConfiguration; import lombok.Getter; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.cobbzilla.util.collection.NameAndValue; import org.cobbzilla.util.string.StringUtil; @@ -47,7 +48,29 @@ public class StandardAccountMessageService implements AccountMessageService { @Autowired private CloudServiceDAO cloudDAO; @Autowired private BubbleConfiguration configuration; + /** + * If returns true, then email/sms will NOT be sent out for this AccountMessage object. + */ + private boolean isQuietMessage(@NonNull final AccountMessage message) { + if (message.getMessageType() == AccountMessageType.confirmation + && message.getAction() == AccountAction.welcome + && message.getTarget() == ActionTarget.account) { + // No need for confirmation message here. The end user received `request.welcome.account` message with email + // address verification link. When he clicked the link, then the request was approved. That was the only + // required approval, and so it was also confirmed at that moment. Hence, AccountMessage + // `confirmation.welcome.account` is created. But there no real need to send out email at this point to the + // same user. And so this other confirmation message is `quiet`. + return true; + } + return false; + } + @Override public boolean send(AccountMessage message) { + if (isQuietMessage(message)) { + log.info("send(" + message + "): message marked as quiet"); + return false; + } + final String accountUuid = message.getAccount(); final Account account = accountDAO.findByUuid(accountUuid); AccountPolicy policy = policyDAO.findSingleByAccount(accountUuid);