Skip to content

Commit

Permalink
fix code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid committed Feb 24, 2024
1 parent e4ee958 commit 4a615ff
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 19 deletions.
14 changes: 5 additions & 9 deletions packages/backend/src/core/NoteReadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,11 @@ export class NoteReadService implements OnApplicationShutdown {
): Promise<void> {
if (notes.length === 0) return;

const noteIds = new Set<MiNote['id']>();

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<MiNote['id']>(
notes.filter(note =>
(note.mentions?.includes(userId) ?? false) || (note.visibleUserIds?.includes(userId) ?? false)
).map(note => note.id),
);

if (noteIds.size === 0) return;

Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ export class NoteReactionEntityService implements OnModuleInit {
withNote: boolean;
},
) : Promise<Packed<'NoteReaction'>[]> {
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/server/api/endpoints/pinned-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/server/api/endpoints/users/reactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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);
Expand Down

0 comments on commit 4a615ff

Please sign in to comment.