TLの抽出条件調節

This commit is contained in:
samunohito 2024-06-12 06:59:53 +09:00
parent ae485ed568
commit a56c680136
2 changed files with 35 additions and 15 deletions

View File

@ -5,7 +5,7 @@
import { Brackets } from 'typeorm'; import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository, ChannelFollowingsRepository } from '@/models/_.js'; import type { ChannelFollowingsRepository, NotesRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js'; import { Endpoint } from '@/server/api/endpoint-base.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
@ -77,10 +77,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor( constructor(
@Inject(DI.notesRepository) @Inject(DI.notesRepository)
private notesRepository: NotesRepository, private notesRepository: NotesRepository,
@Inject(DI.channelFollowingsRepository) @Inject(DI.channelFollowingsRepository)
private channelFollowingsRepository: ChannelFollowingsRepository, private channelFollowingsRepository: ChannelFollowingsRepository,
private noteEntityService: NoteEntityService, private noteEntityService: NoteEntityService,
private roleService: RoleService, private roleService: RoleService,
private activeUsersChart: ActiveUsersChart, private activeUsersChart: ActiveUsersChart,
@ -191,9 +189,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
followerId: me.id, followerId: me.id,
}, },
}); });
const mutingChannelIds = (followingChannels.length > 0) const mutingChannelIds = await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id));
? await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id))
: [];
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
@ -224,11 +220,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
if (mutingChannelIds.length > 0) { if (mutingChannelIds.length > 0) {
// ミュートしてるチャンネルは含めない
query.andWhere(new Brackets(qb => { query.andWhere(new Brackets(qb => {
qb qb
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds }) // ミュートしてるチャンネルは含めない
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds }); .where(new Brackets(qb2 => {
qb2
.andWhere(new Brackets(qb3 => {
qb3
.andWhere('note.channelId IS NOT NULL')
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}))
.andWhere(new Brackets(qb3 => {
qb3
.andWhere('note.renoteChannelId IS NOT NULL')
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}));
}))
// チャンネルの投稿ではない
.orWhere('note.channelId IS NULL');
})); }));
} }

View File

@ -149,9 +149,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
followerId: me.id, followerId: me.id,
}, },
}); });
const mutingChannelIds = (followingChannels.length > 0) const mutingChannelIds = await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id));
? await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id))
: [];
//#region Construct query //#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
@ -200,11 +198,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
if (mutingChannelIds.length > 0) { if (mutingChannelIds.length > 0) {
// ミュートしてるチャンネルは含めない
query.andWhere(new Brackets(qb => { query.andWhere(new Brackets(qb => {
qb qb
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds }) // ミュートしてるチャンネルは含めない
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds }); .where(new Brackets(qb2 => {
qb2
.andWhere(new Brackets(qb3 => {
qb3
.andWhere('note.channelId IS NOT NULL')
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}))
.andWhere(new Brackets(qb3 => {
qb3
.andWhere('note.renoteChannelId IS NOT NULL')
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}));
}))
// チャンネルの投稿ではない
.orWhere('note.channelId IS NULL');
})); }));
} }