From 7731a343d7956250d674b96a4534b01f48c95905 Mon Sep 17 00:00:00 2001 From: biss Date: Mon, 10 Aug 2026 17:06:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E5=B7=B2=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationsControllerTests.cs | 47 +++++++++++++++++++ web/src/views/NotificationCenterView.vue | 13 ++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/Jiaowu.Api.Tests/NotificationsControllerTests.cs b/tests/Jiaowu.Api.Tests/NotificationsControllerTests.cs index be9acf1..22864dd 100644 --- a/tests/Jiaowu.Api.Tests/NotificationsControllerTests.cs +++ b/tests/Jiaowu.Api.Tests/NotificationsControllerTests.cs @@ -234,6 +234,53 @@ public sealed class NotificationsControllerTests Assert.Equal(fixture.ClassStudentUser.Id, notification.UserId); } + [Fact] + public async Task Mark_all_read_only_updates_the_current_users_unread_notifications() + { + await using var fixture = await NotificationFixture.CreateAsync(); + fixture.Db.Notifications.AddRange( + new Notification + { + UserId = fixture.Sender.Id, + Title = "当前用户未读", + Content = "应被标为已读。" + }, + new Notification + { + UserId = fixture.Sender.Id, + Title = "当前用户已读", + Content = "应保持已读。", + IsRead = true + }, + new Notification + { + UserId = fixture.CollegeRecipient.Id, + Title = "其他用户未读", + Content = "不应被修改。" + }); + await fixture.Db.SaveChangesAsync(); + + var controller = new NotificationsController( + fixture.Db, + new TestDataScope( + fixture.Sender.Id, + fixture.FirstCollege.Id, + SystemRoles.AcademicAdmin)); + + var result = await controller.MarkAllRead(CancellationToken.None); + + Assert.IsType(result); + var notifications = await fixture.Db.Notifications.AsNoTracking() + .OrderBy(x => x.Title) + .ToListAsync(); + Assert.All( + notifications.Where(x => x.UserId == fixture.Sender.Id), + notification => Assert.True(notification.IsRead)); + Assert.False(Assert.Single( + notifications, + x => x.UserId == fixture.CollegeRecipient.Id).IsRead); + } + [Fact] public async Task Publishing_course_grades_automatically_notifies_roster_students() { diff --git a/web/src/views/NotificationCenterView.vue b/web/src/views/NotificationCenterView.vue index c064ca1..d2c9425 100644 --- a/web/src/views/NotificationCenterView.vue +++ b/web/src/views/NotificationCenterView.vue @@ -58,6 +58,7 @@ const unreadCount = ref(0) const total = ref(0) const sentTotal = ref(0) const loading = ref(false) +const markingAllRead = ref(false) const sending = ref(false) const composerLoading = ref(false) const recipientLoading = ref(false) @@ -380,6 +381,8 @@ async function openNotification(notification: any) { } async function markAllRead() { + if (markingAllRead.value) return + markingAllRead.value = true try { await http.post('/notifications/read-all') notifications.value.forEach(notification => { @@ -389,6 +392,8 @@ async function markAllRead() { ElMessage.success('全部消息已标为已读') } catch (error) { ElMessage.error(apiErrorMessage(error)) + } finally { + markingAllRead.value = false } } @@ -541,7 +546,13 @@ onMounted(() => load()) @clear="load(true)" /> 仅看未读 - + 全部已读