hide restricted edit history from mastodon api (resolves #811)
This commit is contained in:
parent
bd95e8a555
commit
3550ce27d5
5 changed files with 65 additions and 10 deletions
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
import type { MiNote, NotesRepository } from '@/models/_.js';
|
||||
import type { MiLocalUser } from '@/models/User.js';
|
||||
|
||||
/**
|
||||
* Utility service for accessing data with Mastodon semantics
|
||||
*/
|
||||
@Injectable()
|
||||
export class MastodonDataService {
|
||||
constructor(
|
||||
@Inject(DI.notesRepository)
|
||||
private readonly notesRepository: NotesRepository,
|
||||
|
||||
@Inject(QueryService)
|
||||
private readonly queryService: QueryService,
|
||||
) {}
|
||||
|
||||
public async getNote(noteId: string, me?: MiLocalUser | null): Promise<MiNote | null> {
|
||||
// Root query: note + required dependencies
|
||||
const query = this.notesRepository
|
||||
.createQueryBuilder('note')
|
||||
.where('note.id = :noteId', { noteId })
|
||||
.innerJoinAndSelect('note.user', 'user');
|
||||
|
||||
// Restrict visibility
|
||||
this.queryService.generateVisibilityQuery(query, me);
|
||||
if (me) {
|
||||
this.queryService.generateBlockedUserQuery(query, me);
|
||||
}
|
||||
|
||||
return await query.getOne();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue