From fdf2b8cd0b34983275eef5318c25c04ec0af50ed Mon Sep 17 00:00:00 2001 From: samunohito <46447427+samunohito@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:21:00 +0900 Subject: [PATCH] =?UTF-8?q?Channel=E3=82=B9=E3=82=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=81=AB=E3=83=9F=E3=83=A5=E3=83=BC=E3=83=88=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/entities/ChannelEntityService.ts | 24 ++++++++++++++++++- .../backend/src/models/json-schema/channel.ts | 4 ++++ packages/misskey-js/src/autogen/types.ts | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/entities/ChannelEntityService.ts b/packages/backend/src/core/entities/ChannelEntityService.ts index 71676865c6..bae3d5c117 100644 --- a/packages/backend/src/core/entities/ChannelEntityService.ts +++ b/packages/backend/src/core/entities/ChannelEntityService.ts @@ -8,7 +8,7 @@ import { In } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { ChannelFavoritesRepository, - ChannelFollowingsRepository, + ChannelFollowingsRepository, ChannelMutingRepository, ChannelsRepository, DriveFilesRepository, MiDriveFile, @@ -33,6 +33,8 @@ export class ChannelEntityService { private channelFollowingsRepository: ChannelFollowingsRepository, @Inject(DI.channelFavoritesRepository) private channelFavoritesRepository: ChannelFavoritesRepository, + @Inject(DI.channelMutingRepository) + private channelMutingRepository: ChannelMutingRepository, @Inject(DI.notesRepository) private notesRepository: NotesRepository, @Inject(DI.driveFilesRepository) @@ -52,6 +54,7 @@ export class ChannelEntityService { bannerFiles?: Map; followings?: Set; favorites?: Set; + muting?: Set; pinnedNotes?: Map; }, ): Promise> { @@ -65,6 +68,7 @@ export class ChannelEntityService { let isFollowing = false; let isFavorite = false; + let isMuting = false; if (me) { isFollowing = opts?.followings?.has(channel.id) ?? await this.channelFollowingsRepository.exists({ where: { @@ -79,6 +83,13 @@ export class ChannelEntityService { channelId: channel.id, }, }); + + isMuting = opts?.muting?.has(channel.id) ?? await this.channelMutingRepository.exists({ + where: { + userId: me.id, + channelId: channel.id, + }, + }); } const pinnedNotes = Array.of(); @@ -112,6 +123,7 @@ export class ChannelEntityService { ...(me ? { isFollowing, isFavorite, + isMuting, hasUnreadNote: false, // 後方互換性のため } : {}), @@ -162,6 +174,15 @@ export class ChannelEntityService { .then(it => new Set(it.map(it => it.channelId))) : new Set(); + const muting = me + ? await this.channelMutingRepository + .findBy({ + userId: me.id, + channelId: In(channels.map(it => it.id)), + }) + .then(it => new Set(it.map(it => it.channelId))) + : new Set(); + const pinnedNotes = await this.notesRepository .find({ where: { @@ -174,6 +195,7 @@ export class ChannelEntityService { bannerFiles, followings, favorites, + muting, pinnedNotes, }))); } diff --git a/packages/backend/src/models/json-schema/channel.ts b/packages/backend/src/models/json-schema/channel.ts index d233f7858d..a7966ffdb3 100644 --- a/packages/backend/src/models/json-schema/channel.ts +++ b/packages/backend/src/models/json-schema/channel.ts @@ -80,6 +80,10 @@ export const packedChannelSchema = { type: 'boolean', optional: true, nullable: false, }, + isMuting: { + type: 'boolean', + optional: true, nullable: false, + }, pinnedNotes: { type: 'array', optional: true, nullable: false, diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 8859667df1..80a68ac8b4 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -4542,6 +4542,7 @@ export type components = { allowRenoteToExternal: boolean; isFollowing?: boolean; isFavorited?: boolean; + isMuting?: boolean; pinnedNotes?: components['schemas']['Note'][]; }; QueueCount: {