check for blocks in following / followers endpoints

This commit is contained in:
Hazel K 2024-10-04 20:57:24 -04:00 committed by Hazelnoot
parent c566fa1f36
commit 8f0df1f01c
2 changed files with 16 additions and 2 deletions

View File

@ -5,10 +5,11 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { FollowingsRepository } from '@/models/_.js';
import { MiBlocking, type FollowingsRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
export const meta = {
tags: ['federation'],
@ -48,11 +49,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
private roleService: RoleService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followeeHost = :host', { host: ps.host });
if (!await this.roleService.isModerator(me)) {
query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followerId" AND blocking."blockeeId" = :me', { me: me.id });
query.andWhere('blocking.id IS NULL');
}
const followings = await query
.limit(ps.limit)
.getMany();

View File

@ -5,10 +5,11 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { FollowingsRepository } from '@/models/_.js';
import { MiBlocking, type FollowingsRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
export const meta = {
tags: ['federation'],
@ -48,11 +49,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
private roleService: RoleService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followerHost = :host', { host: ps.host });
if (!await this.roleService.isModerator(me)) {
query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me', { me: me.id });
query.andWhere('blocking.id IS NULL');
}
const followings = await query
.limit(ps.limit)
.getMany();