新增消息一键已读

This commit is contained in:
2026-08-10 17:06:15 +08:00 Unverified
parent 834574accb
commit 7731a343d7
2 changed files with 59 additions and 1 deletions
@@ -234,6 +234,53 @@ public sealed class NotificationsControllerTests
Assert.Equal(fixture.ClassStudentUser.Id, notification.UserId); 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<NoContentResult>(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] [Fact]
public async Task Publishing_course_grades_automatically_notifies_roster_students() public async Task Publishing_course_grades_automatically_notifies_roster_students()
{ {
+12 -1
View File
@@ -58,6 +58,7 @@ const unreadCount = ref(0)
const total = ref(0) const total = ref(0)
const sentTotal = ref(0) const sentTotal = ref(0)
const loading = ref(false) const loading = ref(false)
const markingAllRead = ref(false)
const sending = ref(false) const sending = ref(false)
const composerLoading = ref(false) const composerLoading = ref(false)
const recipientLoading = ref(false) const recipientLoading = ref(false)
@@ -380,6 +381,8 @@ async function openNotification(notification: any) {
} }
async function markAllRead() { async function markAllRead() {
if (markingAllRead.value) return
markingAllRead.value = true
try { try {
await http.post('/notifications/read-all') await http.post('/notifications/read-all')
notifications.value.forEach(notification => { notifications.value.forEach(notification => {
@@ -389,6 +392,8 @@ async function markAllRead() {
ElMessage.success('全部消息已标为已读') ElMessage.success('全部消息已标为已读')
} catch (error) { } catch (error) {
ElMessage.error(apiErrorMessage(error)) ElMessage.error(apiErrorMessage(error))
} finally {
markingAllRead.value = false
} }
} }
@@ -541,7 +546,13 @@ onMounted(() => load())
@clear="load(true)" @clear="load(true)"
/> />
<el-checkbox v-model="unreadOnly" @change="load(true)">仅看未读</el-checkbox> <el-checkbox v-model="unreadOnly" @change="load(true)">仅看未读</el-checkbox>
<el-button v-if="unreadCount" :icon="Check" text @click="markAllRead"> <el-button
v-if="unreadCount"
:icon="Check"
:loading="markingAllRead"
text
@click="markAllRead"
>
全部已读 全部已读
</el-button> </el-button>
</section> </section>