mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-22 14:04:08 +02:00
feat: チャンネルミュートの実装 (#14105)
* add channel_muting table and entities
* add channel_muting services
* タイムライン取得処理への組み込み
* misskey-jsの型とインターフェース生成
* Channelスキーマにミュート情報を追加
* フロントエンドの実装
* 条件が逆だったのを修正
* 期限切れミュートを掃除する機能を実装
* TLの抽出条件調節
* 名前の変更と変更不要の差分をロールバック
* 修正漏れ
* isChannelRelatedの条件に誤りがあった
* [wip] テスト追加
* テストの追加と検出した不備の修正
* fix test
* fix CHANGELOG.md
* 通常はFTTにしておく
* 実装忘れ対応
* fix merge
* fix merge
* add channel tl test
* fix CHANGELOG.md
* remove unused import
* fix lint
* fix test
* fix favorite -> favorited
* exclude -> include
* fix CHANGELOG.md
* fix CHANGELOG.md
* maintenance
* fix CHANGELOG.md
* fix
* fix ci
* regenerate
* fix
* Revert "fix"
This reverts commit 699d50c6ec.
* fixed
---------
Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
@@ -4,36 +4,40 @@
|
||||
*/
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { In } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { ChannelFavoritesRepository, ChannelFollowingsRepository, ChannelsRepository, DriveFilesRepository, NotesRepository } from '@/models/_.js';
|
||||
import type {
|
||||
ChannelFavoritesRepository,
|
||||
ChannelFollowingsRepository, ChannelMutingRepository,
|
||||
ChannelsRepository,
|
||||
DriveFilesRepository,
|
||||
MiDriveFile,
|
||||
MiNote,
|
||||
NotesRepository,
|
||||
} from '@/models/_.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import type { } from '@/models/Blocking.js';
|
||||
import type { MiUser } from '@/models/User.js';
|
||||
import type { MiChannel } from '@/models/Channel.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import { DriveFileEntityService } from './DriveFileEntityService.js';
|
||||
import { NoteEntityService } from './NoteEntityService.js';
|
||||
import { In } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class ChannelEntityService {
|
||||
constructor(
|
||||
@Inject(DI.channelsRepository)
|
||||
private channelsRepository: ChannelsRepository,
|
||||
|
||||
@Inject(DI.channelFollowingsRepository)
|
||||
private channelFollowingsRepository: ChannelFollowingsRepository,
|
||||
|
||||
@Inject(DI.channelFavoritesRepository)
|
||||
private channelFavoritesRepository: ChannelFavoritesRepository,
|
||||
|
||||
@Inject(DI.channelMutingRepository)
|
||||
private channelMutingRepository: ChannelMutingRepository,
|
||||
@Inject(DI.notesRepository)
|
||||
private notesRepository: NotesRepository,
|
||||
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
private noteEntityService: NoteEntityService,
|
||||
private driveFileEntityService: DriveFileEntityService,
|
||||
private idService: IdService,
|
||||
@@ -45,31 +49,59 @@ export class ChannelEntityService {
|
||||
src: MiChannel['id'] | MiChannel,
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
detailed?: boolean,
|
||||
opts?: {
|
||||
bannerFiles?: Map<MiDriveFile['id'], MiDriveFile>;
|
||||
followings?: Set<MiChannel['id']>;
|
||||
favorites?: Set<MiChannel['id']>;
|
||||
muting?: Set<MiChannel['id']>;
|
||||
pinnedNotes?: Map<MiNote['id'], MiNote>;
|
||||
},
|
||||
): Promise<Packed<'Channel'>> {
|
||||
const channel = typeof src === 'object' ? src : await this.channelsRepository.findOneByOrFail({ id: src });
|
||||
const meId = me ? me.id : null;
|
||||
|
||||
const banner = channel.bannerId ? await this.driveFilesRepository.findOneBy({ id: channel.bannerId }) : null;
|
||||
let bannerFile: MiDriveFile | null = null;
|
||||
if (channel.bannerId) {
|
||||
bannerFile = opts?.bannerFiles?.get(channel.bannerId)
|
||||
?? await this.driveFilesRepository.findOneByOrFail({ id: channel.bannerId });
|
||||
}
|
||||
|
||||
const isFollowing = meId ? await this.channelFollowingsRepository.exists({
|
||||
where: {
|
||||
followerId: meId,
|
||||
followeeId: channel.id,
|
||||
},
|
||||
}) : false;
|
||||
let isFollowing = false;
|
||||
let isFavorited = false;
|
||||
let isMuting = false;
|
||||
if (me) {
|
||||
isFollowing = opts?.followings?.has(channel.id) ?? await this.channelFollowingsRepository.exists({
|
||||
where: {
|
||||
followerId: me.id,
|
||||
followeeId: channel.id,
|
||||
},
|
||||
});
|
||||
|
||||
const isFavorited = meId ? await this.channelFavoritesRepository.exists({
|
||||
where: {
|
||||
userId: meId,
|
||||
channelId: channel.id,
|
||||
},
|
||||
}) : false;
|
||||
isFavorited = opts?.favorites?.has(channel.id) ?? await this.channelFavoritesRepository.exists({
|
||||
where: {
|
||||
userId: me.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
});
|
||||
|
||||
const pinnedNotes = channel.pinnedNoteIds.length > 0 ? await this.notesRepository.find({
|
||||
where: {
|
||||
id: In(channel.pinnedNoteIds),
|
||||
},
|
||||
}) : [];
|
||||
isMuting = opts?.muting?.has(channel.id) ?? await this.channelMutingRepository.exists({
|
||||
where: {
|
||||
userId: me.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const pinnedNotes = Array.of<MiNote>();
|
||||
if (channel.pinnedNoteIds.length > 0) {
|
||||
pinnedNotes.push(
|
||||
...(
|
||||
opts?.pinnedNotes
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
? channel.pinnedNoteIds.map(it => opts.pinnedNotes!.get(it)).filter(it => it != null)
|
||||
: await this.notesRepository.findBy({ id: In(channel.pinnedNoteIds) })
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
id: channel.id,
|
||||
@@ -78,7 +110,7 @@ export class ChannelEntityService {
|
||||
name: channel.name,
|
||||
description: channel.description,
|
||||
userId: channel.userId,
|
||||
bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
||||
bannerUrl: bannerFile ? this.driveFileEntityService.getPublicUrl(bannerFile) : null,
|
||||
pinnedNoteIds: channel.pinnedNoteIds,
|
||||
color: channel.color,
|
||||
isArchived: channel.isArchived,
|
||||
@@ -90,6 +122,7 @@ export class ChannelEntityService {
|
||||
...(me ? {
|
||||
isFollowing,
|
||||
isFavorited,
|
||||
isMuting,
|
||||
hasUnreadNote: false, // 後方互換性のため
|
||||
} : {}),
|
||||
|
||||
@@ -98,5 +131,72 @@ export class ChannelEntityService {
|
||||
} : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packMany(
|
||||
src: MiChannel['id'][] | MiChannel[],
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
detailed?: boolean,
|
||||
): Promise<Packed<'Channel'>[]> {
|
||||
// IDのみの要素がある場合、DBからオブジェクトを取得して補う
|
||||
const channels = src.filter(it => typeof it === 'object') as MiChannel[];
|
||||
channels.push(
|
||||
...(await this.channelsRepository.find({
|
||||
where: {
|
||||
id: In(src.filter(it => typeof it !== 'object') as MiChannel['id'][]),
|
||||
},
|
||||
})),
|
||||
);
|
||||
channels.sort((a, b) => a.id.localeCompare(b.id));
|
||||
|
||||
const bannerFiles = await this.driveFilesRepository
|
||||
.findBy({
|
||||
id: In(channels.map(it => it.bannerId).filter(it => it != null)),
|
||||
})
|
||||
.then(it => new Map(it.map(it => [it.id, it])));
|
||||
|
||||
const followings = me
|
||||
? await this.channelFollowingsRepository
|
||||
.findBy({
|
||||
followerId: me.id,
|
||||
followeeId: In(channels.map(it => it.id)),
|
||||
})
|
||||
.then(it => new Set(it.map(it => it.followeeId)))
|
||||
: new Set<MiChannel['id']>();
|
||||
|
||||
const favorites = me
|
||||
? await this.channelFavoritesRepository
|
||||
.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 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
|
||||
.find({
|
||||
where: {
|
||||
id: In(channels.flatMap(it => it.pinnedNoteIds)),
|
||||
},
|
||||
})
|
||||
.then(it => new Map(it.map(it => [it.id, it])));
|
||||
|
||||
return Promise.all(channels.map(it => this.pack(it, me, detailed, {
|
||||
bannerFiles,
|
||||
followings,
|
||||
favorites,
|
||||
muting,
|
||||
pinnedNotes,
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user