diff --git a/backend/src/main/java/com/openisle/model/NotificationType.java b/backend/src/main/java/com/openisle/model/NotificationType.java
index 97a9c7368..d9735bc29 100644
--- a/backend/src/main/java/com/openisle/model/NotificationType.java
+++ b/backend/src/main/java/com/openisle/model/NotificationType.java
@@ -34,6 +34,8 @@ public enum NotificationType {
ACTIVITY_REDEEM,
/** You won a lottery post */
LOTTERY_WIN,
+ /** Your lottery post was drawn */
+ LOTTERY_DRAW,
/** You were mentioned in a post or comment */
MENTION
}
diff --git a/backend/src/main/java/com/openisle/service/PostService.java b/backend/src/main/java/com/openisle/service/PostService.java
index 0b53ecb5d..7b2558e43 100644
--- a/backend/src/main/java/com/openisle/service/PostService.java
+++ b/backend/src/main/java/com/openisle/service/PostService.java
@@ -254,6 +254,13 @@ public class PostService {
notificationService.createNotification(w, NotificationType.LOTTERY_WIN, lp, null, null, lp.getAuthor(), null, null);
notificationService.sendCustomPush(w, "你中奖了", String.format("%s/posts/%d", websiteUrl, lp.getId()));
}
+ if (lp.getAuthor() != null) {
+ if (lp.getAuthor().getEmail() != null) {
+ emailSender.sendEmail(lp.getAuthor().getEmail(), "抽奖已开奖", "您的抽奖贴 \"" + lp.getTitle() + "\" 已开奖");
+ }
+ notificationService.createNotification(lp.getAuthor(), NotificationType.LOTTERY_DRAW, lp, null, null, null, null, null);
+ notificationService.sendCustomPush(lp.getAuthor(), "抽奖已开奖", String.format("%s/posts/%d", websiteUrl, lp.getId()));
+ }
});
}
diff --git a/backend/src/test/java/com/openisle/service/PostServiceTest.java b/backend/src/test/java/com/openisle/service/PostServiceTest.java
index 315fd0fb2..e1dbfd297 100644
--- a/backend/src/test/java/com/openisle/service/PostServiceTest.java
+++ b/backend/src/test/java/com/openisle/service/PostServiceTest.java
@@ -93,4 +93,50 @@ class PostServiceTest {
() -> service.createPost("alice", 1L, "t", "c", List.of(1L),
null, null, null, null, null, null));
}
+
+ @Test
+ void finalizeLotteryNotifiesAuthor() {
+ PostRepository postRepo = mock(PostRepository.class);
+ UserRepository userRepo = mock(UserRepository.class);
+ CategoryRepository catRepo = mock(CategoryRepository.class);
+ TagRepository tagRepo = mock(TagRepository.class);
+ LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
+ NotificationService notifService = mock(NotificationService.class);
+ SubscriptionService subService = mock(SubscriptionService.class);
+ CommentService commentService = mock(CommentService.class);
+ CommentRepository commentRepo = mock(CommentRepository.class);
+ ReactionRepository reactionRepo = mock(ReactionRepository.class);
+ PostSubscriptionRepository subRepo = mock(PostSubscriptionRepository.class);
+ NotificationRepository notificationRepo = mock(NotificationRepository.class);
+ PostReadService postReadService = mock(PostReadService.class);
+ ImageUploader imageUploader = mock(ImageUploader.class);
+ TaskScheduler taskScheduler = mock(TaskScheduler.class);
+ EmailSender emailSender = mock(EmailSender.class);
+ ApplicationContext context = mock(ApplicationContext.class);
+
+ PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
+ notifService, subService, commentService, commentRepo,
+ reactionRepo, subRepo, notificationRepo, postReadService,
+ imageUploader, taskScheduler, emailSender, context, PublishMode.DIRECT);
+ when(context.getBean(PostService.class)).thenReturn(service);
+
+ User author = new User();
+ author.setId(1L);
+ User winner = new User();
+ winner.setId(2L);
+
+ LotteryPost lp = new LotteryPost();
+ lp.setId(1L);
+ lp.setAuthor(author);
+ lp.setTitle("L");
+ lp.setPrizeCount(1);
+ lp.getParticipants().add(winner);
+
+ when(lotteryRepo.findById(1L)).thenReturn(Optional.of(lp));
+
+ service.finalizeLottery(1L);
+
+ verify(notifService).createNotification(eq(winner), eq(NotificationType.LOTTERY_WIN), eq(lp), isNull(), isNull(), eq(author), isNull(), isNull());
+ verify(notifService).createNotification(eq(author), eq(NotificationType.LOTTERY_DRAW), eq(lp), isNull(), isNull(), isNull(), isNull(), isNull());
+ }
}
diff --git a/frontend_nuxt/pages/message.vue b/frontend_nuxt/pages/message.vue
index f154dd7be..063861ee6 100644
--- a/frontend_nuxt/pages/message.vue
+++ b/frontend_nuxt/pages/message.vue
@@ -198,6 +198,19 @@
中获奖
+
+
+ 您的抽奖贴
+
+ {{ stripMarkdownLength(item.post.title, 100) }}
+
+ 已开奖
+
+
您关注的帖子
@@ -579,6 +592,7 @@ export default {
REGISTER_REQUEST: 'fas fa-user-clock',
ACTIVITY_REDEEM: 'fas fa-coffee',
LOTTERY_WIN: 'fas fa-trophy',
+ LOTTERY_DRAW: 'fas fa-bullhorn',
MENTION: 'fas fa-at',
}
@@ -647,6 +661,17 @@ export default {
}
},
})
+ } else if (n.type === 'LOTTERY_DRAW') {
+ notifications.value.push({
+ ...n,
+ icon: iconMap[n.type],
+ iconClick: () => {
+ if (n.post) {
+ markRead(n.id)
+ router.push(`/posts/${n.post.id}`)
+ }
+ },
+ })
} else if (n.type === 'POST_UPDATED') {
notifications.value.push({
...n,
@@ -818,6 +843,8 @@ export default {
return '有人申请兑换奶茶'
case 'LOTTERY_WIN':
return '抽奖中奖了'
+ case 'LOTTERY_DRAW':
+ return '抽奖已开奖'
default:
return t
}