From 4a615ff251af9ba510d68589d4cc41fac386cc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Sun, 25 Feb 2024 03:58:59 +0900 Subject: [PATCH] fix code quality issues --- packages/backend/src/core/NoteReadService.ts | 14 +++++--------- .../backend/src/core/activitypub/ApInboxService.ts | 3 +-- .../src/core/entities/NoteReactionEntityService.ts | 4 +--- .../server/api/endpoints/gallery/posts/create.ts | 1 - .../server/api/endpoints/gallery/posts/update.ts | 1 - .../src/server/api/endpoints/pinned-users.ts | 1 - .../src/server/api/endpoints/users/reactions.ts | 4 ++-- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/core/NoteReadService.ts b/packages/backend/src/core/NoteReadService.ts index 181c9f7649d8..f15dcfd8a1b2 100644 --- a/packages/backend/src/core/NoteReadService.ts +++ b/packages/backend/src/core/NoteReadService.ts @@ -90,15 +90,11 @@ export class NoteReadService implements OnApplicationShutdown { ): Promise { if (notes.length === 0) return; - const noteIds = new Set(); - - for (const note of notes) { - if (note.mentions && note.mentions.includes(userId)) { - noteIds.add(note.id); - } else if (note.visibleUserIds && note.visibleUserIds.includes(userId)) { - noteIds.add(note.id); - } - } + const noteIds = new Set( + notes.filter(note => + (note.mentions?.includes(userId) ?? false) || (note.visibleUserIds?.includes(userId) ?? false) + ).map(note => note.id), + ); if (noteIds.size === 0) return; diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index 200b223ec162..e27797fca6c8 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -28,6 +28,7 @@ import type { UsersRepository, NotesRepository, FollowingsRepository, AbuseUserR import { bindThis } from '@/decorators.js'; import type { MiLocalUser, MiRemoteUser } from '@/models/User.js'; import { isNotNull } from '@/misc/is-not-null.js'; +import { GlobalEventService } from '@/core/GlobalEventService.js'; import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js'; import { ApNoteService } from './models/ApNoteService.js'; import { ApLoggerService } from './ApLoggerService.js'; @@ -36,8 +37,6 @@ import { ApResolverService } from './ApResolverService.js'; import { ApAudienceService } from './ApAudienceService.js'; import { ApPersonService } from './models/ApPersonService.js'; import { ApQuestionService } from './models/ApQuestionService.js'; -import { CacheService } from '@/core/CacheService.js'; -import { GlobalEventService } from '@/core/GlobalEventService.js'; import type { Resolver } from './ApResolverService.js'; import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove } from './type.js'; diff --git a/packages/backend/src/core/entities/NoteReactionEntityService.ts b/packages/backend/src/core/entities/NoteReactionEntityService.ts index f87752ab055c..fa544e4190b9 100644 --- a/packages/backend/src/core/entities/NoteReactionEntityService.ts +++ b/packages/backend/src/core/entities/NoteReactionEntityService.ts @@ -77,9 +77,7 @@ export class NoteReactionEntityService implements OnModuleInit { withNote: boolean; }, ) : Promise[]> { - const opts = Object.assign({ - withNote: false, - }, options); + const opts = { withNote: false, ...options }; return (await Promise.allSettled(reactions.map(x => this.pack(x, me, opts)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts index a10bcc6fb6db..46b101376f71 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts @@ -8,7 +8,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { DriveFilesRepository, GalleryPostsRepository } from '@/models/_.js'; import { MiGalleryPost } from '@/models/GalleryPost.js'; -import type { MiDriveFile } from '@/models/DriveFile.js'; import { IdService } from '@/core/IdService.js'; import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js'; import { DI } from '@/di-symbols.js'; diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts index 16c1c870ca5c..dc5d297cf0c9 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts @@ -7,7 +7,6 @@ import ms from 'ms'; import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { DriveFilesRepository, GalleryPostsRepository } from '@/models/_.js'; -import type { MiDriveFile } from '@/models/DriveFile.js'; import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js'; import { DI } from '@/di-symbols.js'; import { isNotNull } from '@/misc/is-not-null.js'; diff --git a/packages/backend/src/server/api/endpoints/pinned-users.ts b/packages/backend/src/server/api/endpoints/pinned-users.ts index 784766bcb551..f2846b3808f7 100644 --- a/packages/backend/src/server/api/endpoints/pinned-users.ts +++ b/packages/backend/src/server/api/endpoints/pinned-users.ts @@ -7,7 +7,6 @@ import { IsNull } from 'typeorm'; import { Inject, Injectable } from '@nestjs/common'; import type { UsersRepository } from '@/models/_.js'; import * as Acct from '@/misc/acct.js'; -import type { MiUser } from '@/models/User.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { MetaService } from '@/core/MetaService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; diff --git a/packages/backend/src/server/api/endpoints/users/reactions.ts b/packages/backend/src/server/api/endpoints/users/reactions.ts index 9c8c98b4c9c6..917f5efa8977 100644 --- a/packages/backend/src/server/api/endpoints/users/reactions.ts +++ b/packages/backend/src/server/api/endpoints/users/reactions.ts @@ -97,10 +97,10 @@ export default class extends Endpoint { // eslint- qb .from(this.noteReactionsRepository.metadata.targetName, 'reaction') .where('"reaction"."userId" = :userId', { userId: ps.userId }), - ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate + ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate, ), 'reaction', - '"reaction"."noteId" = note.id' + '"reaction"."noteId" = note.id', ); this.queryService.generateVisibilityQuery(query, me);