pack(Many) の me が optional にならないように

This commit is contained in:
riku6460 2023-10-11 04:59:17 +09:00
parent 1a5ba39329
commit df0a663283
No known key found for this signature in database
GPG key ID: 27414FA27DB94CF6
26 changed files with 36 additions and 35 deletions

View file

@ -93,7 +93,7 @@ export class AnnouncementService {
userId: values.userId, userId: values.userId,
}).then(x => this.announcementsRepository.findOneByOrFail(x.identifiers[0])); }).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) { if (values.userId) {
this.globalEventService.publishMainStream(values.userId, 'announcementCreated', { this.globalEventService.publishMainStream(values.userId, 'announcementCreated', {
@ -366,7 +366,7 @@ export class AnnouncementService {
@bindThis @bindThis
public async packMany( public async packMany(
announcements: (MiAnnouncement & { isRead?: boolean | null })[], announcements: (MiAnnouncement & { isRead?: boolean | null })[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Announcement'>[]> { ): Promise<Packed<'Announcement'>[]> {
return announcements.map(announcement => ({ return announcements.map(announcement => ({
id: announcement.id, id: announcement.id,

View file

@ -188,7 +188,7 @@ export class QueryService {
} }
@bindThis @bindThis
public generateVisibilityQuery(q: SelectQueryBuilder<any>, me?: { id: MiUser['id'] } | null): void { public generateVisibilityQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] } | null): void {
// This code must always be synchronized with the checks in Notes.isVisibleForMe. // This code must always be synchronized with the checks in Notes.isVisibleForMe.
if (me == null) { if (me == null) {
q.andWhere(new Brackets(qb => { q.andWhere(new Brackets(qb => {

View file

@ -119,7 +119,7 @@ export class UserListService implements OnApplicationShutdown {
}); });
this.globalEventService.publishInternalEvent('userListMemberRemoved', { userListId: list.id, memberId: target.id }); 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 @bindThis

View file

@ -25,7 +25,7 @@ export class AppEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiApp['id'] | MiApp, src: MiApp['id'] | MiApp,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
options?: { options?: {
detail?: boolean, detail?: boolean,
includeSecret?: boolean, includeSecret?: boolean,

View file

@ -25,7 +25,7 @@ export class AuthSessionEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiAuthSession['id'] | MiAuthSession, 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 }); const session = typeof src === 'object' ? src : await this.authSessionsRepository.findOneByOrFail({ id: src });

View file

@ -26,7 +26,7 @@ export class BlockingEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiBlocking['id'] | MiBlocking, src: MiBlocking['id'] | MiBlocking,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Blocking'>> { ): Promise<Packed<'Blocking'>> {
const blocking = typeof src === 'object' ? src : await this.blockingsRepository.findOneByOrFail({ id: src }); const blocking = typeof src === 'object' ? src : await this.blockingsRepository.findOneByOrFail({ id: src });

View file

@ -44,7 +44,7 @@ export class ChannelEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiChannel['id'] | MiChannel, src: MiChannel['id'] | MiChannel,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
detailed?: boolean, detailed?: boolean,
): Promise<Packed<'Channel'>> { ): Promise<Packed<'Channel'>> {
const channel = typeof src === 'object' ? src : await this.channelsRepository.findOneByOrFail({ id: src }); const channel = typeof src === 'object' ? src : await this.channelsRepository.findOneByOrFail({ id: src });

View file

@ -29,7 +29,7 @@ export class ClipEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiClip['id'] | MiClip, src: MiClip['id'] | MiClip,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Clip'>> { ): Promise<Packed<'Clip'>> {
const meId = me ? me.id : null; const meId = me ? me.id : null;
const clip = typeof src === 'object' ? src : await this.clipsRepository.findOneByOrFail({ id: src }); const clip = typeof src === 'object' ? src : await this.clipsRepository.findOneByOrFail({ id: src });
@ -51,7 +51,7 @@ export class ClipEntityService {
@bindThis @bindThis
public async packMany( public async packMany(
clips: (MiClip['id'] | MiClip)[], clips: (MiClip['id'] | MiClip)[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'Clip'>[]> { ) : Promise<Packed<'Clip'>[]> {
return (await Promise.allSettled(clips.map(x => this.pack(x, me)))) return (await Promise.allSettled(clips.map(x => this.pack(x, me))))
.filter(result => result.status === 'fulfilled') .filter(result => result.status === 'fulfilled')

View file

@ -30,7 +30,7 @@ export class FlashEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiFlash['id'] | MiFlash, src: MiFlash['id'] | MiFlash,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Flash'>> { ): Promise<Packed<'Flash'>> {
const meId = me ? me.id : null; const meId = me ? me.id : null;
const flash = typeof src === 'object' ? src : await this.flashsRepository.findOneByOrFail({ id: src }); const flash = typeof src === 'object' ? src : await this.flashsRepository.findOneByOrFail({ id: src });
@ -52,7 +52,7 @@ export class FlashEntityService {
@bindThis @bindThis
public async packMany( public async packMany(
flashs: MiFlash[], flashs: MiFlash[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'Flash'>[]> { ) : Promise<Packed<'Flash'>[]> {
return (await Promise.allSettled(flashs.map(x => this.pack(x, me)))) return (await Promise.allSettled(flashs.map(x => this.pack(x, me))))
.filter(result => result.status === 'fulfilled') .filter(result => result.status === 'fulfilled')

View file

@ -26,7 +26,7 @@ export class FlashLikeEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiFlashLike['id'] | MiFlashLike, src: MiFlashLike['id'] | MiFlashLike,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'FlashLike'>> { ) : Promise<Packed<'FlashLike'>> {
const like = typeof src === 'object' ? src : await this.flashLikesRepository.findOneByOrFail({ id: src }); const like = typeof src === 'object' ? src : await this.flashLikesRepository.findOneByOrFail({ id: src });

View file

@ -26,7 +26,7 @@ export class FollowRequestEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiFollowRequest['id'] | MiFollowRequest, src: MiFollowRequest['id'] | MiFollowRequest,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'FollowRequest'>> { ) : Promise<Packed<'FollowRequest'>> {
const request = typeof src === 'object' ? src : await this.followRequestsRepository.findOneByOrFail({ id: src }); const request = typeof src === 'object' ? src : await this.followRequestsRepository.findOneByOrFail({ id: src });

View file

@ -71,7 +71,7 @@ export class FollowingEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiFollowing['id'] | MiFollowing, src: MiFollowing['id'] | MiFollowing,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
opts?: { opts?: {
populateFollowee?: boolean; populateFollowee?: boolean;
populateFollower?: boolean; populateFollower?: boolean;
@ -98,7 +98,7 @@ export class FollowingEntityService {
@bindThis @bindThis
public async packMany( public async packMany(
followings: (MiFollowing['id'] | MiFollowing)[], followings: (MiFollowing['id'] | MiFollowing)[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
opts?: { opts?: {
populateFollowee?: boolean; populateFollowee?: boolean;
populateFollower?: boolean; populateFollower?: boolean;

View file

@ -32,7 +32,7 @@ export class GalleryPostEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiGalleryPost['id'] | MiGalleryPost, src: MiGalleryPost['id'] | MiGalleryPost,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'GalleryPost'>> { ): Promise<Packed<'GalleryPost'>> {
const meId = me ? me.id : null; const meId = me ? me.id : null;
const post = typeof src === 'object' ? src : await this.galleryPostsRepository.findOneByOrFail({ id: src }); const post = typeof src === 'object' ? src : await this.galleryPostsRepository.findOneByOrFail({ id: src });
@ -58,7 +58,7 @@ export class GalleryPostEntityService {
@bindThis @bindThis
public async packMany( public async packMany(
posts: MiGalleryPost[], posts: MiGalleryPost[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'GalleryPost'>[]> { ) : Promise<Packed<'GalleryPost'>[]> {
return (await Promise.allSettled(posts.map(x => this.pack(x, me)))) return (await Promise.allSettled(posts.map(x => this.pack(x, me))))
.filter(result => result.status === 'fulfilled') .filter(result => result.status === 'fulfilled')

View file

@ -26,7 +26,7 @@ export class InviteCodeEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiRegistrationTicket['id'] | MiRegistrationTicket, src: MiRegistrationTicket['id'] | MiRegistrationTicket,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'InviteCode'>> { ): Promise<Packed<'InviteCode'>> {
const target = typeof src === 'object' ? src : await this.registrationTicketsRepository.findOneOrFail({ const target = typeof src === 'object' ? src : await this.registrationTicketsRepository.findOneOrFail({
where: { where: {

View file

@ -27,7 +27,7 @@ export class MutingEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiMuting['id'] | MiMuting, src: MiMuting['id'] | MiMuting,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Muting'>> { ): Promise<Packed<'Muting'>> {
const muting = typeof src === 'object' ? src : await this.mutingsRepository.findOneByOrFail({ id: src }); const muting = typeof src === 'object' ? src : await this.mutingsRepository.findOneByOrFail({ id: src });

View file

@ -275,7 +275,7 @@ export class NoteEntityService implements OnModuleInit {
@bindThis @bindThis
public async pack( public async pack(
src: MiNote['id'] | MiNote, src: MiNote['id'] | MiNote,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
options?: { options?: {
detail?: boolean; detail?: boolean;
skipHide?: boolean; skipHide?: boolean;
@ -396,7 +396,7 @@ export class NoteEntityService implements OnModuleInit {
@bindThis @bindThis
public async packMany( public async packMany(
notes: MiNote[], notes: MiNote[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
options?: { options?: {
detail?: boolean; detail?: boolean;
skipHide?: boolean; skipHide?: boolean;

View file

@ -26,7 +26,7 @@ export class NoteFavoriteEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiNoteFavorite['id'] | MiNoteFavorite, src: MiNoteFavorite['id'] | MiNoteFavorite,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'NoteFavorite'>> { ) : Promise<Packed<'NoteFavorite'>> {
const favorite = typeof src === 'object' ? src : await this.noteFavoritesRepository.findOneByOrFail({ id: src }); const favorite = typeof src === 'object' ? src : await this.noteFavoritesRepository.findOneByOrFail({ id: src });

View file

@ -44,7 +44,7 @@ export class NoteReactionEntityService implements OnModuleInit {
@bindThis @bindThis
public async pack( public async pack(
src: MiNoteReaction['id'] | MiNoteReaction, src: MiNoteReaction['id'] | MiNoteReaction,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
options?: { options?: {
withNote: boolean; withNote: boolean;
}, },

View file

@ -36,7 +36,7 @@ export class PageEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiPage['id'] | MiPage, src: MiPage['id'] | MiPage,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'Page'>> { ): Promise<Packed<'Page'>> {
const meId = me ? me.id : null; const meId = me ? me.id : null;
const page = typeof src === 'object' ? src : await this.pagesRepository.findOneByOrFail({ id: src }); const page = typeof src === 'object' ? src : await this.pagesRepository.findOneByOrFail({ id: src });
@ -109,7 +109,7 @@ export class PageEntityService {
@bindThis @bindThis
public async packMany( public async packMany(
pages: (MiPage['id'] | MiPage)[], pages: (MiPage['id'] | MiPage)[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'Page'>[]> { ) : Promise<Packed<'Page'>[]> {
return (await Promise.allSettled(pages.map(x => this.pack(x, me)))) return (await Promise.allSettled(pages.map(x => this.pack(x, me))))
.filter(result => result.status === 'fulfilled') .filter(result => result.status === 'fulfilled')

View file

@ -26,7 +26,7 @@ export class PageLikeEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiPageLike['id'] | MiPageLike, src: MiPageLike['id'] | MiPageLike,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'PageLike'>> { ) : Promise<Packed<'PageLike'>> {
const like = typeof src === 'object' ? src : await this.pageLikesRepository.findOneByOrFail({ id: src }); const like = typeof src === 'object' ? src : await this.pageLikesRepository.findOneByOrFail({ id: src });

View file

@ -27,7 +27,7 @@ export class RenoteMutingEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiRenoteMuting['id'] | MiRenoteMuting, src: MiRenoteMuting['id'] | MiRenoteMuting,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'RenoteMuting'>> { ): Promise<Packed<'RenoteMuting'>> {
const muting = typeof src === 'object' ? src : await this.renoteMutingsRepository.findOneByOrFail({ id: src }); const muting = typeof src === 'object' ? src : await this.renoteMutingsRepository.findOneByOrFail({ id: src });

View file

@ -28,7 +28,7 @@ export class RoleEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: MiRole['id'] | MiRole, src: MiRole['id'] | MiRole,
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'Role'>> { ) : Promise<Packed<'Role'>> {
const role = typeof src === 'object' ? src : await this.rolesRepository.findOneByOrFail({ id: src }); const role = typeof src === 'object' ? src : await this.rolesRepository.findOneByOrFail({ id: src });

View file

@ -289,7 +289,7 @@ export class UserEntityService implements OnModuleInit {
public async pack<ExpectsMe extends boolean | null = null, D extends boolean = false>( public async pack<ExpectsMe extends boolean | null = null, D extends boolean = false>(
src: MiUser['id'] | MiUser, src: MiUser['id'] | MiUser,
me?: { id: MiUser['id']; } | null | undefined, me: { id: MiUser['id']; } | null | undefined,
options?: { options?: {
detail?: D, detail?: D,
includeSecrets?: boolean, includeSecrets?: boolean,
@ -494,7 +494,7 @@ export class UserEntityService implements OnModuleInit {
public async packMany<D extends boolean = false>( public async packMany<D extends boolean = false>(
users: (MiUser['id'] | MiUser)[], users: (MiUser['id'] | MiUser)[],
me?: { id: MiUser['id'] } | null | undefined, me: { id: MiUser['id'] } | null | undefined,
options?: { options?: {
detail?: D, detail?: D,
includeSecrets?: boolean, includeSecrets?: boolean,

View file

@ -5,7 +5,7 @@
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js'; 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 { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js'; import type { } from '@/models/Blocking.js';
import type { MiUserList } from '@/models/UserList.js'; import type { MiUserList } from '@/models/UserList.js';
@ -47,12 +47,13 @@ export class UserListEntityService {
@bindThis @bindThis
public async packMembershipsMany( public async packMembershipsMany(
memberships: MiUserListMembership[], memberships: MiUserListMembership[],
me: { id: MiUser['id']; } | null | undefined,
) { ) {
return Promise.all(memberships.map(async x => ({ return Promise.all(memberships.map(async x => ({
id: x.id, id: x.id,
createdAt: x.createdAt.toISOString(), createdAt: x.createdAt.toISOString(),
userId: x.userId, userId: x.userId,
user: await this.userEntityService.pack(x.userId), user: await this.userEntityService.pack(x.userId, me),
withReplies: x.withReplies, withReplies: x.withReplies,
}))); })));
} }

View file

@ -56,7 +56,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.limit(ps.limit) .limit(ps.limit)
.getMany(); .getMany();
return await this.flashEntityService.packMany(flashs); return await this.flashEntityService.packMany(flashs, me);
}); });
} }
} }

View file

@ -73,7 +73,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.limit(ps.limit) .limit(ps.limit)
.getMany(); .getMany();
return this.userListEntityService.packMembershipsMany(memberships); return this.userListEntityService.packMembershipsMany(memberships, me);
}); });
} }
} }