fix(SearchService): private note is showing on search result
This commit is contained in:
parent
ccbbdc3dbe
commit
981d708bcb
1 changed files with 27 additions and 13 deletions
|
@ -16,6 +16,7 @@ import { isUserRelated } from '@/misc/is-user-related.js';
|
||||||
import { CacheService } from '@/core/CacheService.js';
|
import { CacheService } from '@/core/CacheService.js';
|
||||||
import { QueryService } from '@/core/QueryService.js';
|
import { QueryService } from '@/core/QueryService.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
|
import { UserEntityService } from './entities/UserEntityService.js';
|
||||||
import type { Index, MeiliSearch } from 'meilisearch';
|
import type { Index, MeiliSearch } from 'meilisearch';
|
||||||
|
|
||||||
type K = string;
|
type K = string;
|
||||||
|
@ -76,6 +77,7 @@ export class SearchService {
|
||||||
@Inject(DI.notesRepository)
|
@Inject(DI.notesRepository)
|
||||||
private notesRepository: NotesRepository,
|
private notesRepository: NotesRepository,
|
||||||
|
|
||||||
|
private userEntityService: UserEntityService,
|
||||||
private cacheService: CacheService,
|
private cacheService: CacheService,
|
||||||
private queryService: QueryService,
|
private queryService: QueryService,
|
||||||
private idService: IdService,
|
private idService: IdService,
|
||||||
|
@ -149,13 +151,35 @@ export class SearchService {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async unindexNote(note: MiNote): Promise<void> {
|
public async unindexNote(note: MiNote): Promise<void> {
|
||||||
if (!['home', 'public'].includes(note.visibility)) return;
|
// if (!['home', 'public'].includes(note.visibility)) return;
|
||||||
|
|
||||||
if (this.meilisearch) {
|
if (this.meilisearch) {
|
||||||
this.meilisearchNoteIndex!.deleteDocument(note.id);
|
this.meilisearchNoteIndex!.deleteDocument(note.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
private async filter(me: MiUser | null, note: MiNote): Promise<boolean> {
|
||||||
|
const [
|
||||||
|
userIdsWhoMeMuting,
|
||||||
|
userIdsWhoBlockingMe,
|
||||||
|
] = me ? await Promise.all([
|
||||||
|
this.cacheService.userMutingsCache.fetch(me.id),
|
||||||
|
this.cacheService.userBlockedCache.fetch(me.id),
|
||||||
|
]) : [new Set<string>(), new Set<string>()];
|
||||||
|
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
||||||
|
if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
|
||||||
|
if (['followers', 'specified'].includes(note.visibility)) {
|
||||||
|
if (!me) return false;
|
||||||
|
if (note.visibility === 'followers') {
|
||||||
|
const relationship = await this.userEntityService.getRelation(me.id, note.userId);
|
||||||
|
if (relationship.isFollowing) return true;
|
||||||
|
}
|
||||||
|
if (!note.visibleUserIds.includes(me.id) && !note.mentions.includes(me.id)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async searchNote(q: string, me: MiUser | null, opts: {
|
public async searchNote(q: string, me: MiUser | null, opts: {
|
||||||
userId?: MiNote['userId'] | null;
|
userId?: MiNote['userId'] | null;
|
||||||
|
@ -190,20 +214,10 @@ export class SearchService {
|
||||||
limit: pagination.limit,
|
limit: pagination.limit,
|
||||||
});
|
});
|
||||||
if (res.hits.length === 0) return [];
|
if (res.hits.length === 0) return [];
|
||||||
const [
|
|
||||||
userIdsWhoMeMuting,
|
|
||||||
userIdsWhoBlockingMe,
|
|
||||||
] = me ? await Promise.all([
|
|
||||||
this.cacheService.userMutingsCache.fetch(me.id),
|
|
||||||
this.cacheService.userBlockedCache.fetch(me.id),
|
|
||||||
]) : [new Set<string>(), new Set<string>()];
|
|
||||||
const notes = (await this.notesRepository.findBy({
|
const notes = (await this.notesRepository.findBy({
|
||||||
id: In(res.hits.map(x => x.id)),
|
id: In(res.hits.map(x => x.id)),
|
||||||
})).filter(note => {
|
})).filter(async note => (await this.filter(me, note)));
|
||||||
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
|
||||||
if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
||||||
} else {
|
} else {
|
||||||
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue