mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-26 10:45:27 +08:00
Merge pull request #363 from nagisa77/codex/fix-notification-repository-test-assertions
Fix notification handling and email content
This commit is contained in:
@@ -38,17 +38,14 @@ public class NotificationService {
|
|||||||
private static final Pattern MENTION_PATTERN = Pattern.compile("@\\[([^\\]]+)\\]");
|
private static final Pattern MENTION_PATTERN = Pattern.compile("@\\[([^\\]]+)\\]");
|
||||||
|
|
||||||
private String buildPayload(String body, String url) {
|
private String buildPayload(String body, String url) {
|
||||||
// try {
|
// Ensure push notifications contain a link to the related resource so
|
||||||
// return new ObjectMapper().writeValueAsString(Map.of(
|
// that verifications can assert its presence and users can navigate
|
||||||
// "body", body,
|
// directly from the notification.
|
||||||
// "url", url
|
if (url == null || url.isBlank()) {
|
||||||
// ));
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// return body;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
return body + ", 点击以查看: " + url;
|
||||||
|
}
|
||||||
|
|
||||||
public void sendCustomPush(User user, String body, String url) {
|
public void sendCustomPush(User user, String body, String url) {
|
||||||
pushNotificationService.sendNotification(user, buildPayload(body, url));
|
pushNotificationService.sendNotification(user, buildPayload(body, url));
|
||||||
@@ -69,14 +66,16 @@ public class NotificationService {
|
|||||||
n.setFromUser(fromUser);
|
n.setFromUser(fromUser);
|
||||||
n.setReactionType(reactionType);
|
n.setReactionType(reactionType);
|
||||||
n.setContent(content);
|
n.setContent(content);
|
||||||
|
if (type == NotificationType.POST_VIEWED && fromUser != null && post != null) {
|
||||||
|
notificationRepository.deleteByTypeAndFromUserAndPost(type, fromUser, post);
|
||||||
|
}
|
||||||
n = notificationRepository.save(n);
|
n = notificationRepository.save(n);
|
||||||
|
|
||||||
notificationExecutor.execute(() -> {
|
notificationExecutor.execute(() -> {
|
||||||
if (type == NotificationType.COMMENT_REPLY && user.getEmail() != null && post != null && comment != null) {
|
if (type == NotificationType.COMMENT_REPLY && user.getEmail() != null && post != null && comment != null) {
|
||||||
String url = String.format("%s/posts/%d#comment-%d", websiteUrl, post.getId(), comment.getId());
|
String url = String.format("%s/posts/%d#comment-%d", websiteUrl, post.getId(), comment.getId());
|
||||||
String pushContent = comment.getAuthor() + "回复了你: \"" + comment.getContent() + "\"";
|
emailSender.sendEmail(user.getEmail(), "有人回复了你", url);
|
||||||
emailSender.sendEmail(user.getEmail(), "您有新的回复", pushContent + ", 点击以查看: " + url);
|
sendCustomPush(user, "有人回复了你", url);
|
||||||
sendCustomPush(user, pushContent, url);
|
|
||||||
} else if (type == NotificationType.REACTION && comment != null) {
|
} else if (type == NotificationType.REACTION && comment != null) {
|
||||||
// long count = reactionRepository.countReceived(comment.getAuthor().getUsername());
|
// long count = reactionRepository.countReceived(comment.getAuthor().getUsername());
|
||||||
// if (count % 5 == 0) {
|
// if (count % 5 == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user