Channelスキーマにミュート情報を追加

This commit is contained in:
samunohito 2024-06-11 21:21:00 +09:00
parent a46fefd43c
commit fdf2b8cd0b
3 changed files with 28 additions and 1 deletions

View File

@ -8,7 +8,7 @@ import { In } from 'typeorm';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { import type {
ChannelFavoritesRepository, ChannelFavoritesRepository,
ChannelFollowingsRepository, ChannelFollowingsRepository, ChannelMutingRepository,
ChannelsRepository, ChannelsRepository,
DriveFilesRepository, DriveFilesRepository,
MiDriveFile, MiDriveFile,
@ -33,6 +33,8 @@ export class ChannelEntityService {
private channelFollowingsRepository: ChannelFollowingsRepository, private channelFollowingsRepository: ChannelFollowingsRepository,
@Inject(DI.channelFavoritesRepository) @Inject(DI.channelFavoritesRepository)
private channelFavoritesRepository: ChannelFavoritesRepository, private channelFavoritesRepository: ChannelFavoritesRepository,
@Inject(DI.channelMutingRepository)
private channelMutingRepository: ChannelMutingRepository,
@Inject(DI.notesRepository) @Inject(DI.notesRepository)
private notesRepository: NotesRepository, private notesRepository: NotesRepository,
@Inject(DI.driveFilesRepository) @Inject(DI.driveFilesRepository)
@ -52,6 +54,7 @@ export class ChannelEntityService {
bannerFiles?: Map<MiDriveFile['id'], MiDriveFile>; bannerFiles?: Map<MiDriveFile['id'], MiDriveFile>;
followings?: Set<MiChannel['id']>; followings?: Set<MiChannel['id']>;
favorites?: Set<MiChannel['id']>; favorites?: Set<MiChannel['id']>;
muting?: Set<MiChannel['id']>;
pinnedNotes?: Map<MiNote['id'], MiNote>; pinnedNotes?: Map<MiNote['id'], MiNote>;
}, },
): Promise<Packed<'Channel'>> { ): Promise<Packed<'Channel'>> {
@ -65,6 +68,7 @@ export class ChannelEntityService {
let isFollowing = false; let isFollowing = false;
let isFavorite = false; let isFavorite = false;
let isMuting = false;
if (me) { if (me) {
isFollowing = opts?.followings?.has(channel.id) ?? await this.channelFollowingsRepository.exists({ isFollowing = opts?.followings?.has(channel.id) ?? await this.channelFollowingsRepository.exists({
where: { where: {
@ -79,6 +83,13 @@ export class ChannelEntityService {
channelId: channel.id, channelId: channel.id,
}, },
}); });
isMuting = opts?.muting?.has(channel.id) ?? await this.channelMutingRepository.exists({
where: {
userId: me.id,
channelId: channel.id,
},
});
} }
const pinnedNotes = Array.of<MiNote>(); const pinnedNotes = Array.of<MiNote>();
@ -112,6 +123,7 @@ export class ChannelEntityService {
...(me ? { ...(me ? {
isFollowing, isFollowing,
isFavorite, isFavorite,
isMuting,
hasUnreadNote: false, // 後方互換性のため hasUnreadNote: false, // 後方互換性のため
} : {}), } : {}),
@ -162,6 +174,15 @@ export class ChannelEntityService {
.then(it => new Set(it.map(it => it.channelId))) .then(it => new Set(it.map(it => it.channelId)))
: new Set<MiChannel['id']>(); : new Set<MiChannel['id']>();
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<MiChannel['id']>();
const pinnedNotes = await this.notesRepository const pinnedNotes = await this.notesRepository
.find({ .find({
where: { where: {
@ -174,6 +195,7 @@ export class ChannelEntityService {
bannerFiles, bannerFiles,
followings, followings,
favorites, favorites,
muting,
pinnedNotes, pinnedNotes,
}))); })));
} }

View File

@ -80,6 +80,10 @@ export const packedChannelSchema = {
type: 'boolean', type: 'boolean',
optional: true, nullable: false, optional: true, nullable: false,
}, },
isMuting: {
type: 'boolean',
optional: true, nullable: false,
},
pinnedNotes: { pinnedNotes: {
type: 'array', type: 'array',
optional: true, nullable: false, optional: true, nullable: false,

View File

@ -4542,6 +4542,7 @@ export type components = {
allowRenoteToExternal: boolean; allowRenoteToExternal: boolean;
isFollowing?: boolean; isFollowing?: boolean;
isFavorited?: boolean; isFavorited?: boolean;
isMuting?: boolean;
pinnedNotes?: components['schemas']['Note'][]; pinnedNotes?: components['schemas']['Note'][];
}; };
QueueCount: { QueueCount: {