-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(announcement): 個別のお知らせにリンクで飛べるように (MisskeyIO#639) (cherry picked from commit f6bf7f9) * fix Co-authored-by: まっちゃとーにゅ <[email protected]> * fix Co-authored-by: まっちゃとーにゅ <[email protected]> * 一覧ページではお知らせpanel全体を押せるように * お知らせバーは個別ページに飛ばすように * Update Changelog * spdx * attempt to fox test * remove unnecessary thong * `announcement` → `announcements/show` * リンクを押せる場所をタイトルと日付部分のみに変更 --------- Co-authored-by: まっちゃとーにゅ <[email protected]>
- Loading branch information
1 parent
e0b4799
commit 3ffbf62
Showing
18 changed files
with
415 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/backend/src/core/entities/AnnouncementEntityService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { DI } from '@/di-symbols.js'; | ||
import type { AnnouncementsRepository, AnnouncementReadsRepository, MiAnnouncement, MiUser } from '@/models/_.js'; | ||
import type { Packed } from '@/misc/json-schema.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { IdService } from '@/core/IdService.js'; | ||
|
||
@Injectable() | ||
export class AnnouncementEntityService { | ||
constructor( | ||
@Inject(DI.announcementsRepository) | ||
private announcementsRepository: AnnouncementsRepository, | ||
|
||
@Inject(DI.announcementReadsRepository) | ||
private announcementReadsRepository: AnnouncementReadsRepository, | ||
|
||
private idService: IdService, | ||
) { | ||
} | ||
|
||
@bindThis | ||
public async pack( | ||
src: MiAnnouncement['id'] | MiAnnouncement & { isRead?: boolean | null }, | ||
me?: { id: MiUser['id'] } | null | undefined, | ||
): Promise<Packed<'Announcement'>> { | ||
const announcement = typeof src === 'object' | ||
? src | ||
: await this.announcementsRepository.findOneByOrFail({ | ||
id: src, | ||
}) as MiAnnouncement & { isRead?: boolean | null }; | ||
|
||
if (me && announcement.isRead === undefined) { | ||
announcement.isRead = await this.announcementReadsRepository | ||
.countBy({ | ||
announcementId: announcement.id, | ||
userId: me.id, | ||
}) | ||
.then((count: number) => count > 0); | ||
} | ||
|
||
return { | ||
id: announcement.id, | ||
createdAt: this.idService.parse(announcement.id).date.toISOString(), | ||
updatedAt: announcement.updatedAt?.toISOString() ?? null, | ||
title: announcement.title, | ||
text: announcement.text, | ||
imageUrl: announcement.imageUrl, | ||
icon: announcement.icon, | ||
display: announcement.display, | ||
forYou: announcement.userId === me?.id, | ||
needConfirmationToRead: announcement.needConfirmationToRead, | ||
silence: announcement.silence, | ||
isRead: announcement.isRead !== null ? announcement.isRead : undefined, | ||
}; | ||
} | ||
|
||
@bindThis | ||
public async packMany( | ||
announcements: (MiAnnouncement['id'] | MiAnnouncement & { isRead?: boolean | null } | MiAnnouncement)[], | ||
me?: { id: MiUser['id'] } | null | undefined, | ||
) : Promise<Packed<'Announcement'>[]> { | ||
return (await Promise.allSettled(announcements.map(x => this.pack(x, me)))) | ||
.filter(result => result.status === 'fulfilled') | ||
.map(result => (result as PromiseFulfilledResult<Packed<'Announcement'>>).value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/backend/src/server/api/endpoints/announcements/show.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Injectable } from '@nestjs/common'; | ||
import { EntityNotFoundError } from 'typeorm'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import { AnnouncementService } from '@/core/AnnouncementService.js'; | ||
import { ApiError } from '../../error.js'; | ||
|
||
export const meta = { | ||
tags: ['meta'], | ||
|
||
requireCredential: false, | ||
|
||
res: { | ||
type: 'object', | ||
optional: false, nullable: false, | ||
ref: 'Announcement', | ||
}, | ||
|
||
errors: { | ||
noSuchAnnouncement: { | ||
message: 'No such announcement.', | ||
code: 'NO_SUCH_ANNOUNCEMENT', | ||
id: 'b57b5e1d-4f49-404a-9edb-46b00268f121', | ||
}, | ||
}, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
announcementId: { type: 'string', format: 'misskey:id' }, | ||
}, | ||
required: ['announcementId'], | ||
} as const; | ||
|
||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export | ||
constructor( | ||
private announcementService: AnnouncementService, | ||
) { | ||
super(meta, paramDef, async (ps, me) => { | ||
try { | ||
return await this.announcementService.getAnnouncement(ps.announcementId, me); | ||
} catch (err) { | ||
if (err instanceof EntityNotFoundError) throw new ApiError(meta.errors.noSuchAnnouncement); | ||
throw err; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.