fix(announcement): お知らせ機能の改善・バグ修正 (MisskeyIO#280)

・過去のお知らせでは表示順設定を適用しないように
・過去のお知らせでもわかったボタンが出るように
・お知らせ管理画面では表示順設定を適用しないように
・お知らせ管理画面のページング処理のバグ修正
This commit is contained in:
まっちゃとーにゅ 2023-12-07 08:46:58 +09:00 committed by GitHub
parent ba4f9279fb
commit c31f27e327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 13 deletions

View file

@ -140,6 +140,7 @@ export class AnnouncementService {
moderator: MiUser, moderator: MiUser,
): Promise<(MiAnnouncement & { userInfo: Packed<'UserLite'> | null, reads: number })[]> { ): Promise<(MiAnnouncement & { userInfo: Packed<'UserLite'> | null, reads: number })[]> {
const query = this.announcementsRepository.createQueryBuilder('announcement'); const query = this.announcementsRepository.createQueryBuilder('announcement');
if (userId) { if (userId) {
query.andWhere('announcement."userId" = :userId', { userId: userId }); query.andWhere('announcement."userId" = :userId', { userId: userId });
} else { } else {
@ -148,7 +149,6 @@ export class AnnouncementService {
query.orderBy({ query.orderBy({
'announcement."isActive"': 'DESC', 'announcement."isActive"': 'DESC',
'announcement."displayOrder"': 'DESC',
'announcement.id': 'DESC', 'announcement.id': 'DESC',
}); });
@ -259,9 +259,10 @@ export class AnnouncementService {
me: MiUser | null, me: MiUser | null,
limit: number, limit: number,
offset: number, offset: number,
isActive?: boolean, isActive: boolean,
): Promise<Packed<'Announcement'>[]> { ): Promise<Packed<'Announcement'>[]> {
const query = this.announcementsRepository.createQueryBuilder('announcement'); const query = this.announcementsRepository.createQueryBuilder('announcement');
if (me) { if (me) {
query.leftJoin( query.leftJoin(
MiAnnouncementRead, MiAnnouncementRead,
@ -295,18 +296,22 @@ export class AnnouncementService {
query.andWhere('announcement."forExistingUsers" = false'); query.andWhere('announcement."forExistingUsers" = false');
} }
if (isActive !== undefined) { query.andWhere('announcement."isActive" = :isActive', {
query.andWhere('announcement."isActive" = :isActive', { 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( return this.announcementEntityService.packMany(
await query await query
.limit(limit) .limit(limit)

View file

@ -193,7 +193,7 @@ function fetch(resetOffset = false): void {
}).then(announcementResponse => { }).then(announcementResponse => {
announcements = announcements.concat(announcementResponse); announcements = announcements.concat(announcementResponse);
hasMore.value = announcementResponse?.length === 10; hasMore.value = announcementResponse?.length === 10;
offset.value += announcements.length; offset.value += announcementResponse?.length ?? 0;
}); });
} }

View file

@ -29,7 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkTime :time="announcement.updatedAt ?? announcement.createdAt" mode="detail"/> <MkTime :time="announcement.updatedAt ?? announcement.createdAt" mode="detail"/>
</div> </div>
</div> </div>
<div v-if="tab !== 'past' && $i && !announcement.silence && !announcement.isRead" :class="$style.footer"> <div v-if="$i && !announcement.silence && !announcement.isRead" :class="$style.footer">
<MkButton primary @click="read(announcement)"><i class="ti ti-check"></i> {{ i18n.ts.gotIt }}</MkButton> <MkButton primary @click="read(announcement)"><i class="ti ti-check"></i> {{ i18n.ts.gotIt }}</MkButton>
</div> </div>
</section> </section>