From df0a66328398f3d2f3274f90e7f4168bc3e68f2c Mon Sep 17 00:00:00 2001 From: riku6460 <17585784+riku6460@users.noreply.github.com> Date: Wed, 11 Oct 2023 04:59:17 +0900 Subject: [PATCH] =?UTF-8?q?pack(Many)=20=E3=81=AE=20me=20=E3=81=8C=20optio?= =?UTF-8?q?nal=20=E3=81=AB=E3=81=AA=E3=82=89=E3=81=AA=E3=81=84=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/AnnouncementService.ts | 4 ++-- packages/backend/src/core/QueryService.ts | 2 +- packages/backend/src/core/UserListService.ts | 2 +- packages/backend/src/core/entities/AppEntityService.ts | 2 +- .../backend/src/core/entities/AuthSessionEntityService.ts | 2 +- packages/backend/src/core/entities/BlockingEntityService.ts | 2 +- packages/backend/src/core/entities/ChannelEntityService.ts | 2 +- packages/backend/src/core/entities/ClipEntityService.ts | 4 ++-- packages/backend/src/core/entities/FlashEntityService.ts | 4 ++-- packages/backend/src/core/entities/FlashLikeEntityService.ts | 2 +- .../backend/src/core/entities/FollowRequestEntityService.ts | 2 +- packages/backend/src/core/entities/FollowingEntityService.ts | 4 ++-- .../backend/src/core/entities/GalleryPostEntityService.ts | 4 ++-- .../backend/src/core/entities/InviteCodeEntityService.ts | 2 +- packages/backend/src/core/entities/MutingEntityService.ts | 2 +- packages/backend/src/core/entities/NoteEntityService.ts | 4 ++-- .../backend/src/core/entities/NoteFavoriteEntityService.ts | 2 +- .../backend/src/core/entities/NoteReactionEntityService.ts | 2 +- packages/backend/src/core/entities/PageEntityService.ts | 4 ++-- packages/backend/src/core/entities/PageLikeEntityService.ts | 2 +- .../backend/src/core/entities/RenoteMutingEntityService.ts | 2 +- packages/backend/src/core/entities/RoleEntityService.ts | 2 +- packages/backend/src/core/entities/UserEntityService.ts | 4 ++-- packages/backend/src/core/entities/UserListEntityService.ts | 5 +++-- packages/backend/src/server/api/endpoints/users/flashs.ts | 2 +- .../src/server/api/endpoints/users/lists/get-memberships.ts | 2 +- 26 files changed, 36 insertions(+), 35 deletions(-) diff --git a/packages/backend/src/core/AnnouncementService.ts b/packages/backend/src/core/AnnouncementService.ts index 9c6cda6c0d21..3fafc2cfc259 100644 --- a/packages/backend/src/core/AnnouncementService.ts +++ b/packages/backend/src/core/AnnouncementService.ts @@ -93,7 +93,7 @@ export class AnnouncementService { userId: values.userId, }).then(x => this.announcementsRepository.findOneByOrFail(x.identifiers[0])); - const packed = (await this.packMany([announcement]))[0]; + const packed = (await this.packMany([announcement], null))[0]; if (values.userId) { this.globalEventService.publishMainStream(values.userId, 'announcementCreated', { @@ -366,7 +366,7 @@ export class AnnouncementService { @bindThis public async packMany( announcements: (MiAnnouncement & { isRead?: boolean | null })[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise[]> { return announcements.map(announcement => ({ id: announcement.id, diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts index 50d1d2e65b97..e65b34a9221b 100644 --- a/packages/backend/src/core/QueryService.ts +++ b/packages/backend/src/core/QueryService.ts @@ -188,7 +188,7 @@ export class QueryService { } @bindThis - public generateVisibilityQuery(q: SelectQueryBuilder, me?: { id: MiUser['id'] } | null): void { + public generateVisibilityQuery(q: SelectQueryBuilder, me: { id: MiUser['id'] } | null): void { // This code must always be synchronized with the checks in Notes.isVisibleForMe. if (me == null) { q.andWhere(new Brackets(qb => { diff --git a/packages/backend/src/core/UserListService.ts b/packages/backend/src/core/UserListService.ts index 550a9bf5f22e..8cfea7b589fd 100644 --- a/packages/backend/src/core/UserListService.ts +++ b/packages/backend/src/core/UserListService.ts @@ -119,7 +119,7 @@ export class UserListService implements OnApplicationShutdown { }); this.globalEventService.publishInternalEvent('userListMemberRemoved', { userListId: list.id, memberId: target.id }); - this.globalEventService.publishUserListStream(list.id, 'userRemoved', await this.userEntityService.pack(target)); + this.globalEventService.publishUserListStream(list.id, 'userRemoved', await this.userEntityService.pack(target, null)); } @bindThis diff --git a/packages/backend/src/core/entities/AppEntityService.ts b/packages/backend/src/core/entities/AppEntityService.ts index 14a93cda5ba0..8fec971d75ff 100644 --- a/packages/backend/src/core/entities/AppEntityService.ts +++ b/packages/backend/src/core/entities/AppEntityService.ts @@ -25,7 +25,7 @@ export class AppEntityService { @bindThis public async pack( src: MiApp['id'] | MiApp, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { detail?: boolean, includeSecret?: boolean, diff --git a/packages/backend/src/core/entities/AuthSessionEntityService.ts b/packages/backend/src/core/entities/AuthSessionEntityService.ts index fd356cc89d17..ea35825cbf5c 100644 --- a/packages/backend/src/core/entities/AuthSessionEntityService.ts +++ b/packages/backend/src/core/entities/AuthSessionEntityService.ts @@ -25,7 +25,7 @@ export class AuthSessionEntityService { @bindThis public async pack( src: MiAuthSession['id'] | MiAuthSession, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) { const session = typeof src === 'object' ? src : await this.authSessionsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/BlockingEntityService.ts b/packages/backend/src/core/entities/BlockingEntityService.ts index 11bfd27505b5..82ee71a2dc16 100644 --- a/packages/backend/src/core/entities/BlockingEntityService.ts +++ b/packages/backend/src/core/entities/BlockingEntityService.ts @@ -26,7 +26,7 @@ export class BlockingEntityService { @bindThis public async pack( src: MiBlocking['id'] | MiBlocking, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const blocking = typeof src === 'object' ? src : await this.blockingsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/ChannelEntityService.ts b/packages/backend/src/core/entities/ChannelEntityService.ts index 5224e9d76ce8..7972a06dc5e2 100644 --- a/packages/backend/src/core/entities/ChannelEntityService.ts +++ b/packages/backend/src/core/entities/ChannelEntityService.ts @@ -44,7 +44,7 @@ export class ChannelEntityService { @bindThis public async pack( src: MiChannel['id'] | MiChannel, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, detailed?: boolean, ): Promise> { const channel = typeof src === 'object' ? src : await this.channelsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/ClipEntityService.ts b/packages/backend/src/core/entities/ClipEntityService.ts index e10c828a0adc..4e6adc0db4c8 100644 --- a/packages/backend/src/core/entities/ClipEntityService.ts +++ b/packages/backend/src/core/entities/ClipEntityService.ts @@ -29,7 +29,7 @@ export class ClipEntityService { @bindThis public async pack( src: MiClip['id'] | MiClip, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const meId = me ? me.id : null; const clip = typeof src === 'object' ? src : await this.clipsRepository.findOneByOrFail({ id: src }); @@ -51,7 +51,7 @@ export class ClipEntityService { @bindThis public async packMany( clips: (MiClip['id'] | MiClip)[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise[]> { return (await Promise.allSettled(clips.map(x => this.pack(x, me)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/core/entities/FlashEntityService.ts b/packages/backend/src/core/entities/FlashEntityService.ts index d321483232aa..1219c1c138a3 100644 --- a/packages/backend/src/core/entities/FlashEntityService.ts +++ b/packages/backend/src/core/entities/FlashEntityService.ts @@ -30,7 +30,7 @@ export class FlashEntityService { @bindThis public async pack( src: MiFlash['id'] | MiFlash, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const meId = me ? me.id : null; const flash = typeof src === 'object' ? src : await this.flashsRepository.findOneByOrFail({ id: src }); @@ -52,7 +52,7 @@ export class FlashEntityService { @bindThis public async packMany( flashs: MiFlash[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise[]> { return (await Promise.allSettled(flashs.map(x => this.pack(x, me)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/core/entities/FlashLikeEntityService.ts b/packages/backend/src/core/entities/FlashLikeEntityService.ts index 31807777a878..fe4539627cd5 100644 --- a/packages/backend/src/core/entities/FlashLikeEntityService.ts +++ b/packages/backend/src/core/entities/FlashLikeEntityService.ts @@ -26,7 +26,7 @@ export class FlashLikeEntityService { @bindThis public async pack( src: MiFlashLike['id'] | MiFlashLike, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise> { const like = typeof src === 'object' ? src : await this.flashLikesRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/FollowRequestEntityService.ts b/packages/backend/src/core/entities/FollowRequestEntityService.ts index 0153337ec165..2e3243e8dddc 100644 --- a/packages/backend/src/core/entities/FollowRequestEntityService.ts +++ b/packages/backend/src/core/entities/FollowRequestEntityService.ts @@ -26,7 +26,7 @@ export class FollowRequestEntityService { @bindThis public async pack( src: MiFollowRequest['id'] | MiFollowRequest, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise> { const request = typeof src === 'object' ? src : await this.followRequestsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/FollowingEntityService.ts b/packages/backend/src/core/entities/FollowingEntityService.ts index 2ddcf73f563d..c3ca8dfbb411 100644 --- a/packages/backend/src/core/entities/FollowingEntityService.ts +++ b/packages/backend/src/core/entities/FollowingEntityService.ts @@ -71,7 +71,7 @@ export class FollowingEntityService { @bindThis public async pack( src: MiFollowing['id'] | MiFollowing, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, opts?: { populateFollowee?: boolean; populateFollower?: boolean; @@ -98,7 +98,7 @@ export class FollowingEntityService { @bindThis public async packMany( followings: (MiFollowing['id'] | MiFollowing)[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, opts?: { populateFollowee?: boolean; populateFollower?: boolean; diff --git a/packages/backend/src/core/entities/GalleryPostEntityService.ts b/packages/backend/src/core/entities/GalleryPostEntityService.ts index b962268c1446..19a80270edf8 100644 --- a/packages/backend/src/core/entities/GalleryPostEntityService.ts +++ b/packages/backend/src/core/entities/GalleryPostEntityService.ts @@ -32,7 +32,7 @@ export class GalleryPostEntityService { @bindThis public async pack( src: MiGalleryPost['id'] | MiGalleryPost, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const meId = me ? me.id : null; const post = typeof src === 'object' ? src : await this.galleryPostsRepository.findOneByOrFail({ id: src }); @@ -58,7 +58,7 @@ export class GalleryPostEntityService { @bindThis public async packMany( posts: MiGalleryPost[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise[]> { return (await Promise.allSettled(posts.map(x => this.pack(x, me)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/core/entities/InviteCodeEntityService.ts b/packages/backend/src/core/entities/InviteCodeEntityService.ts index acc7aed91a44..40eb226e8d11 100644 --- a/packages/backend/src/core/entities/InviteCodeEntityService.ts +++ b/packages/backend/src/core/entities/InviteCodeEntityService.ts @@ -26,7 +26,7 @@ export class InviteCodeEntityService { @bindThis public async pack( src: MiRegistrationTicket['id'] | MiRegistrationTicket, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const target = typeof src === 'object' ? src : await this.registrationTicketsRepository.findOneOrFail({ where: { diff --git a/packages/backend/src/core/entities/MutingEntityService.ts b/packages/backend/src/core/entities/MutingEntityService.ts index 2347b804e567..6f9a6ffebcd6 100644 --- a/packages/backend/src/core/entities/MutingEntityService.ts +++ b/packages/backend/src/core/entities/MutingEntityService.ts @@ -27,7 +27,7 @@ export class MutingEntityService { @bindThis public async pack( src: MiMuting['id'] | MiMuting, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const muting = typeof src === 'object' ? src : await this.mutingsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 2a89e9244c72..00b71bd66c99 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -275,7 +275,7 @@ export class NoteEntityService implements OnModuleInit { @bindThis public async pack( src: MiNote['id'] | MiNote, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { detail?: boolean; skipHide?: boolean; @@ -396,7 +396,7 @@ export class NoteEntityService implements OnModuleInit { @bindThis public async packMany( notes: MiNote[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { detail?: boolean; skipHide?: boolean; diff --git a/packages/backend/src/core/entities/NoteFavoriteEntityService.ts b/packages/backend/src/core/entities/NoteFavoriteEntityService.ts index 0da756a6bf68..33ba397e2065 100644 --- a/packages/backend/src/core/entities/NoteFavoriteEntityService.ts +++ b/packages/backend/src/core/entities/NoteFavoriteEntityService.ts @@ -26,7 +26,7 @@ export class NoteFavoriteEntityService { @bindThis public async pack( src: MiNoteFavorite['id'] | MiNoteFavorite, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise> { const favorite = typeof src === 'object' ? src : await this.noteFavoritesRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/NoteReactionEntityService.ts b/packages/backend/src/core/entities/NoteReactionEntityService.ts index 577272296ea0..fcfb90c946dd 100644 --- a/packages/backend/src/core/entities/NoteReactionEntityService.ts +++ b/packages/backend/src/core/entities/NoteReactionEntityService.ts @@ -44,7 +44,7 @@ export class NoteReactionEntityService implements OnModuleInit { @bindThis public async pack( src: MiNoteReaction['id'] | MiNoteReaction, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { withNote: boolean; }, diff --git a/packages/backend/src/core/entities/PageEntityService.ts b/packages/backend/src/core/entities/PageEntityService.ts index 4e5b07adc3cd..092f66e2553e 100644 --- a/packages/backend/src/core/entities/PageEntityService.ts +++ b/packages/backend/src/core/entities/PageEntityService.ts @@ -36,7 +36,7 @@ export class PageEntityService { @bindThis public async pack( src: MiPage['id'] | MiPage, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const meId = me ? me.id : null; const page = typeof src === 'object' ? src : await this.pagesRepository.findOneByOrFail({ id: src }); @@ -109,7 +109,7 @@ export class PageEntityService { @bindThis public async packMany( pages: (MiPage['id'] | MiPage)[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise[]> { return (await Promise.allSettled(pages.map(x => this.pack(x, me)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/core/entities/PageLikeEntityService.ts b/packages/backend/src/core/entities/PageLikeEntityService.ts index 5210b34c13e1..c5200bb82d58 100644 --- a/packages/backend/src/core/entities/PageLikeEntityService.ts +++ b/packages/backend/src/core/entities/PageLikeEntityService.ts @@ -26,7 +26,7 @@ export class PageLikeEntityService { @bindThis public async pack( src: MiPageLike['id'] | MiPageLike, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise> { const like = typeof src === 'object' ? src : await this.pageLikesRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/RenoteMutingEntityService.ts b/packages/backend/src/core/entities/RenoteMutingEntityService.ts index 0707dfbb5c72..5c6e025bb2ce 100644 --- a/packages/backend/src/core/entities/RenoteMutingEntityService.ts +++ b/packages/backend/src/core/entities/RenoteMutingEntityService.ts @@ -27,7 +27,7 @@ export class RenoteMutingEntityService { @bindThis public async pack( src: MiRenoteMuting['id'] | MiRenoteMuting, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ): Promise> { const muting = typeof src === 'object' ? src : await this.renoteMutingsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/RoleEntityService.ts b/packages/backend/src/core/entities/RoleEntityService.ts index 9d335a65d30c..20bb2ae3666d 100644 --- a/packages/backend/src/core/entities/RoleEntityService.ts +++ b/packages/backend/src/core/entities/RoleEntityService.ts @@ -28,7 +28,7 @@ export class RoleEntityService { @bindThis public async pack( src: MiRole['id'] | MiRole, - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, ) : Promise> { const role = typeof src === 'object' ? src : await this.rolesRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 7668d37bcfc5..405fbeebebb5 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -289,7 +289,7 @@ export class UserEntityService implements OnModuleInit { public async pack( src: MiUser['id'] | MiUser, - me?: { id: MiUser['id']; } | null | undefined, + me: { id: MiUser['id']; } | null | undefined, options?: { detail?: D, includeSecrets?: boolean, @@ -494,7 +494,7 @@ export class UserEntityService implements OnModuleInit { public async packMany( users: (MiUser['id'] | MiUser)[], - me?: { id: MiUser['id'] } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { detail?: D, includeSecrets?: boolean, diff --git a/packages/backend/src/core/entities/UserListEntityService.ts b/packages/backend/src/core/entities/UserListEntityService.ts index 06b6e852b146..46cb4f05abc8 100644 --- a/packages/backend/src/core/entities/UserListEntityService.ts +++ b/packages/backend/src/core/entities/UserListEntityService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; -import type { MiUserListMembership, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js'; +import type { MiUser, MiUserListMembership, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js'; import type { Packed } from '@/misc/json-schema.js'; import type { } from '@/models/Blocking.js'; import type { MiUserList } from '@/models/UserList.js'; @@ -47,12 +47,13 @@ export class UserListEntityService { @bindThis public async packMembershipsMany( memberships: MiUserListMembership[], + me: { id: MiUser['id']; } | null | undefined, ) { return Promise.all(memberships.map(async x => ({ id: x.id, createdAt: x.createdAt.toISOString(), userId: x.userId, - user: await this.userEntityService.pack(x.userId), + user: await this.userEntityService.pack(x.userId, me), withReplies: x.withReplies, }))); } diff --git a/packages/backend/src/server/api/endpoints/users/flashs.ts b/packages/backend/src/server/api/endpoints/users/flashs.ts index 18026dcefbaa..c3474c62d067 100644 --- a/packages/backend/src/server/api/endpoints/users/flashs.ts +++ b/packages/backend/src/server/api/endpoints/users/flashs.ts @@ -56,7 +56,7 @@ export default class extends Endpoint { .limit(ps.limit) .getMany(); - return await this.flashEntityService.packMany(flashs); + return await this.flashEntityService.packMany(flashs, me); }); } } diff --git a/packages/backend/src/server/api/endpoints/users/lists/get-memberships.ts b/packages/backend/src/server/api/endpoints/users/lists/get-memberships.ts index ae8b4e9b8124..5ec35c311551 100644 --- a/packages/backend/src/server/api/endpoints/users/lists/get-memberships.ts +++ b/packages/backend/src/server/api/endpoints/users/lists/get-memberships.ts @@ -73,7 +73,7 @@ export default class extends Endpoint { .limit(ps.limit) .getMany(); - return this.userListEntityService.packMembershipsMany(memberships); + return this.userListEntityService.packMembershipsMany(memberships, me); }); } }