diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-12-23 20:00:20 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-23 20:00:20 +0900 |
| commit | 0b5228f3cd48c51cb74f62244d937f9c6182df85 (patch) | |
| tree | 5572817b104bfb83cd00d17dc18132919b35e71d /packages/backend/src/server/api/endpoints/users/featured-notes.ts | |
| parent | Merge pull request #12330 from misskey-dev/develop (diff) | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-0b5228f3cd48c51cb74f62244d937f9c6182df85.tar.gz misskey-0b5228f3cd48c51cb74f62244d937f9c6182df85.tar.bz2 misskey-0b5228f3cd48c51cb74f62244d937f9c6182df85.zip | |
Merge pull request #12564 from misskey-dev/develop
Release: 2023.12.0
Diffstat (limited to 'packages/backend/src/server/api/endpoints/users/featured-notes.ts')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/users/featured-notes.ts | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/packages/backend/src/server/api/endpoints/users/featured-notes.ts b/packages/backend/src/server/api/endpoints/users/featured-notes.ts index dec0b7a122..7243aa3b3e 100644 --- a/packages/backend/src/server/api/endpoints/users/featured-notes.ts +++ b/packages/backend/src/server/api/endpoints/users/featured-notes.ts @@ -9,6 +9,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; import { FeaturedService } from '@/core/FeaturedService.js'; +import { CacheService } from '@/core/CacheService.js'; +import { isUserRelated } from '@/misc/is-user-related.js'; export const meta = { tags: ['notes'], @@ -46,8 +48,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- private noteEntityService: NoteEntityService, private featuredService: FeaturedService, + private cacheService: CacheService, ) { super(meta, paramDef, async (ps, me) => { + const userIdsWhoBlockingMe = me ? await this.cacheService.userBlockedCache.fetch(me.id) : new Set<string>(); + + // early return if me is blocked by requesting user + if (userIdsWhoBlockingMe.has(ps.userId)) { + return []; + } + let noteIds = await this.featuredService.getPerUserNotesRanking(ps.userId, 50); noteIds.sort((a, b) => a > b ? -1 : 1); @@ -60,6 +70,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- return []; } + const [ + userIdsWhoMeMuting, + ] = me ? await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + ]) : [new Set<string>()]; + const query = this.notesRepository.createQueryBuilder('note') .where('note.id IN (:...noteIds)', { noteIds: noteIds }) .innerJoinAndSelect('note.user', 'user') @@ -69,10 +85,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- .leftJoinAndSelect('renote.user', 'renoteUser') .leftJoinAndSelect('note.channel', 'channel'); - const notes = await query.getMany(); - notes.sort((a, b) => a.id > b.id ? -1 : 1); + const notes = (await query.getMany()).filter(note => { + if (me && isUserRelated(note, userIdsWhoBlockingMe, false)) return false; + if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false; - // TODO: ミュート等考慮 + return true; + }); + + notes.sort((a, b) => a.id > b.id ? -1 : 1); return await this.noteEntityService.packMany(notes, me); }); |