feat: 個人宛てお知らせ機能 (#107)

* feat: 個人宛てお知らせ機能

* Remove unused import

* Update packages/backend/src/server/api/endpoints/admin/announcements/create.ts

Co-authored-by: riku6460 <17585784+riku6460@users.noreply.github.com>

* Update packages/frontend/src/pages/announcements.vue

Co-authored-by: riku6460 <17585784+riku6460@users.noreply.github.com>

* Restore breakline

* 一般向けAPIにはuserオブジェクトを提供しない

* fix

* Fix

* Update packages/misskey-js/src/entities.ts

Co-authored-by: riku6460 <17585784+riku6460@users.noreply.github.com>

* Fix

* Update misskey-js.api.md

* Fix lint

* 他のテーブルに合わせて character varying(32) にした

* count クエリを1つにまとめた

* user を pack するようにした

* いろいろ修正

* 個人宛てのお知らせの表示を改善

* Update misskey-js.api.md

* Merge migration scripts

* Fix

* Update packages/backend/migration/1688647797135-userannouncement.js

Co-authored-by: riku6460 <17585784+riku6460@users.noreply.github.com>

* Update packages/backend/src/models/entities/Announcement.ts

Co-authored-by: まっちゃとーにゅ <17376330+u1-liquid@users.noreply.github.com>

* Fix

* Update migration script

---------

Co-authored-by: CyberRex <hspwinx86@gmail.com>
Co-authored-by: まっちゃとーにゅ <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
riku6460 2023-07-24 13:08:39 +09:00 committed by GitHub
parent 6d3f64f606
commit 7b1efd6b97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 374 additions and 18 deletions

View file

@ -48,6 +48,14 @@ export const meta = {
type: 'boolean',
optional: true, nullable: false,
},
isPrivate: {
type: 'boolean',
optional: false, nullable: true,
},
closeDuration: {
type: 'number',
optional: false, nullable: false,
},
},
},
},
@ -60,6 +68,7 @@ export const paramDef = {
withUnreads: { type: 'boolean', default: false },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
privateOnly: { type: 'boolean', default: false },
},
required: [],
} as const;
@ -77,8 +86,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.announcementsRepository.createQueryBuilder('announcement'), ps.sinceId, ps.untilId);
const builder = this.announcementsRepository.createQueryBuilder('announcement');
if (me) {
if (ps.privateOnly) {
builder.where('"userId" = :userId', { userId: me.id });
} else {
builder.where('"userId" IS NULL');
builder.orWhere('"userId" = :userId', { userId: me.id });
}
} else {
builder.where('"userId" IS NULL');
}
const query = this.queryService.makePaginationQuery(builder, ps.sinceId, ps.untilId);
const announcements = await query.limit(ps.limit).getMany();
if (me) {
@ -95,6 +115,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
...a,
createdAt: a.createdAt.toISOString(),
updatedAt: a.updatedAt?.toISOString() ?? null,
isPrivate: !!a.userId,
}));
});
}