mirror of https://github.com/halo-dev/halo
fix: compatible email are empty when comment notification triggered (#4685)
#### What type of PR is this? /kind bug /area core /milestone 2.10.x #### What this PR does / why we need it: 修复当评论或回复者的邮箱为空时通知报错的问题 #### Which issue(s) this PR fixes: Fixes #4684 #### Does this PR introduce a user-facing change? ```release-note 修复当评论或回复者的邮箱为空时通知报错的问题 ```pull/4686/head
parent
d443c3ed29
commit
b2d7221316
|
@ -1,6 +1,8 @@
|
|||
package run.halo.app.content.comment;
|
||||
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.content.NotificationReasonConst;
|
||||
import run.halo.app.core.extension.content.Comment;
|
||||
|
@ -56,13 +58,21 @@ public class ReplyNotificationSubscriptionHelper {
|
|||
void subscribeReply(Subscription.ReasonSubject reasonSubject,
|
||||
Identity identity) {
|
||||
var subscriber = createSubscriber(identity);
|
||||
if (subscriber == null) {
|
||||
return;
|
||||
}
|
||||
var interestReason = new Subscription.InterestReason();
|
||||
interestReason.setReasonType(NotificationReasonConst.SOMEONE_REPLIED_TO_YOU);
|
||||
interestReason.setSubject(reasonSubject);
|
||||
notificationCenter.subscribe(subscriber, interestReason).block();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Subscription.Subscriber createSubscriber(Identity author) {
|
||||
if (StringUtils.isBlank(author.name())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Subscription.Subscriber subscriber;
|
||||
if (author.isEmail()) {
|
||||
subscriber = subscriberEmailResolver.ofEmail(author.name());
|
||||
|
|
|
@ -43,6 +43,11 @@ public class EmailNotifier implements ReactiveNotifier {
|
|||
var emailSenderConfig =
|
||||
JsonUtils.DEFAULT_JSON_MAPPER.convertValue(senderConfig, EmailSenderConfig.class);
|
||||
|
||||
if (!emailSenderConfig.isEnable()) {
|
||||
log.debug("Email notifier is disabled, skip sending email.");
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
JavaMailSenderImpl javaMailSender = getJavaMailSender(emailSenderConfig);
|
||||
|
||||
String recipient = context.getMessage().getRecipient();
|
||||
|
@ -51,6 +56,11 @@ public class EmailNotifier implements ReactiveNotifier {
|
|||
var payload = context.getMessage().getPayload();
|
||||
return subscriberEmailResolver.resolve(subscriber)
|
||||
.flatMap(toEmail -> {
|
||||
if (StringUtils.isBlank(toEmail)) {
|
||||
log.debug("Cannot resolve email for subscriber: [{}], skip sending email.",
|
||||
subscriber);
|
||||
return Mono.empty();
|
||||
}
|
||||
var htmlMono = appendHtmlBodyFooter(payload.getAttributes())
|
||||
.doOnNext(footer -> {
|
||||
if (StringUtils.isNotBlank(payload.getHtmlBody())) {
|
||||
|
@ -138,6 +148,7 @@ public class EmailNotifier implements ReactiveNotifier {
|
|||
|
||||
@Data
|
||||
static class EmailSenderConfig {
|
||||
private boolean enable;
|
||||
private String displayName;
|
||||
private String username;
|
||||
private String password;
|
||||
|
|
|
@ -19,22 +19,31 @@ spec:
|
|||
- group: sender
|
||||
label: 发件设置
|
||||
formSchema:
|
||||
- $formkit: checkbox
|
||||
label: "启用邮件通知器"
|
||||
value: false
|
||||
name: enable
|
||||
- $formkit: text
|
||||
if: "$enable"
|
||||
label: "用户名"
|
||||
name: username
|
||||
validation: required
|
||||
- $formkit: password
|
||||
if: "$enable"
|
||||
label: "密码"
|
||||
name: password
|
||||
validation: required
|
||||
- $formkit: text
|
||||
if: "$enable"
|
||||
label: "显示名称"
|
||||
name: displayName
|
||||
- $formkit: text
|
||||
if: "$enable"
|
||||
label: "SMTP 服务器地址"
|
||||
name: host
|
||||
validation: required
|
||||
- $formkit: text
|
||||
if: "$enable"
|
||||
label: "端口号"
|
||||
name: port
|
||||
validation: required
|
||||
|
|
Loading…
Reference in New Issue