タイムライン取得処理への組み込み

This commit is contained in:
samunohito 2024-06-11 21:13:31 +09:00
parent 94ededa68d
commit 7d7c2d4daf
18 changed files with 512 additions and 43 deletions

View file

@ -6,7 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import Redis from 'ioredis';
import { DI } from '@/di-symbols.js';
import type { ChannelMutingRepository, MiChannel, MiUser } from '@/models/_.js';
import type { ChannelMutingRepository, ChannelsRepository, MiChannel, MiUser } from '@/models/_.js';
import { IdService } from '@/core/IdService.js';
import { GlobalEvents, GlobalEventService } from '@/core/GlobalEventService.js';
import { bindThis } from '@/decorators.js';
@ -21,6 +21,8 @@ export class ChannelMutingService {
private redisClient: Redis.Redis,
@Inject(DI.redisForSub)
private redisForSub: Redis.Redis,
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
@Inject(DI.channelMutingRepository)
private channelMutingRepository: ChannelMutingRepository,
private idService: IdService,
@ -40,6 +42,61 @@ export class ChannelMutingService {
this.redisForSub.on('message', this.onMessage);
}
/**
* .
* @param params
* @param [opts]
* @param {(boolean|undefined)} [opts.joinUser=undefined] JOINするかどうか(falseまたは省略時はJOINしない).
* @param {(boolean|undefined)} [opts.joinBannerFile=undefined] JOINするかどうか(falseまたは省略時はJOINしない).
*/
@bindThis
public async list(
params: {
requestUserId: MiUser['id'],
},
opts?: {
joinUser?: boolean;
joinBannerFile?: boolean;
},
): Promise<MiChannel[]> {
const q = this.channelsRepository.createQueryBuilder('channel')
.innerJoin('channel_muting', 'channel_muting', 'channel_muting.channelId = channel.id')
.where('channel_muting.userId = :userId', { userId: params.requestUserId })
.andWhere(qb => {
qb.where('channel_muting.expiresAt IS NULL')
.orWhere('channel_muting.expiresAt > :now:', { now: new Date() });
});
if (opts?.joinUser) {
q.innerJoinAndSelect('channel.user', 'user');
}
if (opts?.joinBannerFile) {
q.leftJoinAndSelect('channel.banner', 'drive_file');
}
return q.getMany();
}
/**
* .
* @param params
* @param params.requestUserId
*/
@bindThis
public async isMuted(params: {
requestUserId: MiUser['id'],
targetChannelId: MiChannel['id'],
}): Promise<boolean> {
const mutedChannels = await this.userMutingChannelsCache.get(params.requestUserId);
return (mutedChannels?.has(params.targetChannelId) ?? false);
}
/**
* .
* @param params
* @param {(Date|null|undefined)} [params.expiresAt] . nullまたは省略時は無期限.
*/
@bindThis
public async mute(params: {
requestUserId: MiUser['id'],
@ -59,6 +116,10 @@ export class ChannelMutingService {
});
}
/**
* .
* @param params
*/
@bindThis
public async unmute(params: {
requestUserId: MiUser['id'],