diff --git a/packages/backend/src/core/AnnouncementService.ts b/packages/backend/src/core/AnnouncementService.ts index 58b07bef9..45d6a5fcd 100644 --- a/packages/backend/src/core/AnnouncementService.ts +++ b/packages/backend/src/core/AnnouncementService.ts @@ -140,6 +140,7 @@ export class AnnouncementService { moderator: MiUser, ): Promise<(MiAnnouncement & { userInfo: Packed<'UserLite'> | null, reads: number })[]> { const query = this.announcementsRepository.createQueryBuilder('announcement'); + if (userId) { query.andWhere('announcement."userId" = :userId', { userId: userId }); } else { @@ -148,7 +149,6 @@ export class AnnouncementService { query.orderBy({ 'announcement."isActive"': 'DESC', - 'announcement."displayOrder"': 'DESC', 'announcement.id': 'DESC', }); @@ -259,9 +259,10 @@ export class AnnouncementService { me: MiUser | null, limit: number, offset: number, - isActive?: boolean, + isActive: boolean, ): Promise[]> { const query = this.announcementsRepository.createQueryBuilder('announcement'); + if (me) { query.leftJoin( MiAnnouncementRead, @@ -295,18 +296,22 @@ export class AnnouncementService { query.andWhere('announcement."forExistingUsers" = false'); } - if (isActive !== undefined) { - query.andWhere('announcement."isActive" = :isActive', { - isActive: isActive, + query.andWhere('announcement."isActive" = :isActive', { + isActive: isActive, + }); + + if (isActive) { + query.orderBy({ + '"isRead"': 'ASC', + 'announcement."displayOrder"': 'DESC', + 'announcement.id': 'DESC', + }); + } else { + query.orderBy({ + 'announcement.id': 'DESC', }); } - query.orderBy({ - '"isRead"': 'ASC', - 'announcement."displayOrder"': 'DESC', - 'announcement.id': 'DESC', - }); - return this.announcementEntityService.packMany( await query .limit(limit) diff --git a/packages/frontend/src/pages/admin/announcements.vue b/packages/frontend/src/pages/admin/announcements.vue index 0fd52c72d..fdc62d69c 100644 --- a/packages/frontend/src/pages/admin/announcements.vue +++ b/packages/frontend/src/pages/admin/announcements.vue @@ -193,7 +193,7 @@ function fetch(resetOffset = false): void { }).then(announcementResponse => { announcements = announcements.concat(announcementResponse); hasMore.value = announcementResponse?.length === 10; - offset.value += announcements.length; + offset.value += announcementResponse?.length ?? 0; }); } diff --git a/packages/frontend/src/pages/announcements.vue b/packages/frontend/src/pages/announcements.vue index eebd4f19a..1158775e2 100644 --- a/packages/frontend/src/pages/announcements.vue +++ b/packages/frontend/src/pages/announcements.vue @@ -29,7 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only -
+
{{ i18n.ts.gotIt }}