fix(AntennaService): use UserEntityService instead of repository

This commit is contained in:
무라쿠모 2024-05-13 22:14:31 +09:00
parent 4d20fbeb52
commit 1a1fafc43f
No known key found for this signature in database
GPG key ID: 139D6573F92DA9F7
2 changed files with 5 additions and 5 deletions

View file

@ -18,6 +18,7 @@ import { bindThis } from '@/decorators.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js'; import type { GlobalEvents } from '@/core/GlobalEventService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js'; import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { RolePolicies, RoleService } from '@/core/RoleService.js'; import { RolePolicies, RoleService } from '@/core/RoleService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import type { OnApplicationShutdown } from '@nestjs/common'; import type { OnApplicationShutdown } from '@nestjs/common';
@Injectable() @Injectable()
@ -41,6 +42,7 @@ export class AntennaService implements OnApplicationShutdown {
@Inject(DI.userListMembershipsRepository) @Inject(DI.userListMembershipsRepository)
private userListMembershipsRepository: UserListMembershipsRepository, private userListMembershipsRepository: UserListMembershipsRepository,
private userEntityService: UserEntityService,
private utilityService: UtilityService, private utilityService: UtilityService,
private globalEventService: GlobalEventService, private globalEventService: GlobalEventService,
private fanoutTimelineService: FanoutTimelineService, private fanoutTimelineService: FanoutTimelineService,
@ -127,10 +129,8 @@ export class AntennaService implements OnApplicationShutdown {
public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; isBot: boolean; }): Promise<boolean> { public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; isBot: boolean; }): Promise<boolean> {
if (note.visibility === 'specified') return false; if (note.visibility === 'specified') return false;
if (note.visibility === 'followers') { if (note.visibility === 'followers') {
if (!antenna.user) return false; const relationship = await this.userEntityService.getRelation(antenna.userId, noteUser.id);
if (!relationship.isFollowing) return false;
const followingAuthor = await this.followingsRepository.findOneBy({ followeeId: noteUser.id, followerId: antenna.user.id });
if (!followingAuthor) return false;
} }
if (antenna.excludeBots && noteUser.isBot) return false; if (antenna.excludeBots && noteUser.isBot) return false;

View file

@ -142,7 +142,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} else { } else {
const q: FindOptionsWhere<MiUser> = ps.userId != null const q: FindOptionsWhere<MiUser> = ps.userId != null
? { id: ps.userId } ? { id: ps.userId }
: { usernameLower: ps.username!.toLowerCase(), host: IsNull() }; : { usernameLower: ps.username?.toLowerCase(), host: IsNull() };
user = await this.usersRepository.findOneBy(q); user = await this.usersRepository.findOneBy(q);
} }