Skip to content

Commit

Permalink
Revert "enhance: ミュートした人のリアクションが一般的なAPIで表示されないように (#232)"
Browse files Browse the repository at this point in the history
This reverts commit 8309feb.
  • Loading branch information
kanarikanaru committed Feb 1, 2025
1 parent 2c5b571 commit 97b9a6b
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 287 deletions.
10 changes: 1 addition & 9 deletions packages/backend/src/core/FanoutTimelineEndpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { isQuote, isRenote } from '@/misc/is-renote.js';
import { CacheService } from '@/core/CacheService.js';
import { isReply } from '@/misc/is-reply.js';
import { isInstanceMuted } from '@/misc/is-instance-muted.js';
import { removeMutedUsersReactions } from '@/misc/reactions-mute.js';

type TimelineOptions = {
untilId: string | null,
Expand Down Expand Up @@ -51,14 +50,7 @@ export class FanoutTimelineEndpointService {

@bindThis
async timeline(ps: TimelineOptions): Promise<Packed<'Note'>[]> {
const packedNotes = await this.noteEntityService.packMany(await this.getMiNotes(ps), ps.me, ps.me ? { withReactionAndUserPairCache: true } : undefined);
if (ps.me) {
const userIdsWhoMeMuting = await this.cacheService.userMutingsCache.fetch(ps.me.id);
await Promise.all(
packedNotes.map(note => removeMutedUsersReactions(note, userIdsWhoMeMuting)),
);
}
return packedNotes;
return await this.noteEntityService.packMany(await this.getMiNotes(ps), ps.me);
}

@bindThis
Expand Down
59 changes: 18 additions & 41 deletions packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DI } from '@/di-symbols.js';
import { type Config, FulltextSearchProvider } from '@/config.js';
import { bindThis } from '@/decorators.js';
import { MiNote } from '@/models/Note.js';
import { Packed } from '@/misc/json-schema.js';
import type { NotesRepository } from '@/models/_.js';
import { MiUser } from '@/models/_.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
Expand All @@ -18,9 +17,6 @@ import { CacheService } from '@/core/CacheService.js';
import { QueryService } from '@/core/QueryService.js';
import { IdService } from '@/core/IdService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { isMustRemove } from '@/misc/is-hidden-or-visibility-modified.js';
import { removeMutedUsersReactions } from '@/misc/reactions-mute.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import type { Index, MeiliSearch } from 'meilisearch';

type K = string;
Expand Down Expand Up @@ -94,7 +90,6 @@ export class SearchService {
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,

private noteEntityService: NoteEntityService,
private cacheService: CacheService,
private queryService: QueryService,
private idService: IdService,
Expand Down Expand Up @@ -183,24 +178,16 @@ export class SearchService {
me: MiUser | null,
opts: SearchOpts,
pagination: SearchPagination,
): Promise<Packed<'Note'>[]> {
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>()];

): Promise<MiNote[]> {
switch (this.provider) {
case 'sqlLike':
case 'sqlPgroonga': {
// ほとんど内容に差がないのでsqlLikeとsqlPgroongaを同じ処理にしている.
// 今後の拡張で差が出る用であれば関数を分ける.
return this.searchNoteByLike(q, me, opts, pagination, userIdsWhoMeMuting, userIdsWhoBlockingMe);
return this.searchNoteByLike(q, me, opts, pagination);
}
case 'meilisearch': {
return this.searchNoteByMeiliSearch(q, me, opts, pagination, userIdsWhoMeMuting, userIdsWhoBlockingMe);
return this.searchNoteByMeiliSearch(q, me, opts, pagination);
}
default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -216,9 +203,7 @@ export class SearchService {
me: MiUser | null,
opts: SearchOpts,
pagination: SearchPagination,
userIdsWhoMeMuting: Set<string>,
userIdsWhoBlockingMe: Set<string>,
): Promise<Packed<'Note'>[]> {
): Promise<MiNote[]> {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);

if (opts.userId) {
Expand Down Expand Up @@ -249,18 +234,10 @@ export class SearchService {
}

this.queryService.generateVisibilityQuery(query, me);
if (me) this.queryService.generateMutedUserQuery(query, me);
if (me) this.queryService.generateBlockedUserQuery(query, me);

const notes = (await query.getMany()).filter(note => {
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;

return true;
});
const packedNotes = (await this.noteEntityService.packMany(notes, me, { withReactionAndUserPairCache: true })).filter(note => !isMustRemove(note, 'home'));
await Promise.all(
packedNotes.map(note => removeMutedUsersReactions(note, userIdsWhoMeMuting)),
);
return packedNotes;
return query.limit(pagination.limit).getMany();
}

@bindThis
Expand All @@ -269,10 +246,7 @@ export class SearchService {
me: MiUser | null,
opts: SearchOpts,
pagination: SearchPagination,
userIdsWhoMeMuting: Set<string>,
userIdsWhoBlockingMe: Set<string>,

): Promise<Packed<'Note'>[]> {
): Promise<MiNote[]> {
if (!this.meilisearch || !this.meilisearchNoteIndex) {
throw new Error('MeiliSearch is not available');
}
Expand Down Expand Up @@ -312,6 +286,15 @@ export class SearchService {
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({
id: In(res.hits.map(x => x.id)),
})).filter(note => {
Expand All @@ -320,12 +303,6 @@ export class SearchService {
return true;
});

notes.sort((a, b) => a.id > b.id ? -1 : 1);
const packedNotes = (await this.noteEntityService.packMany(notes, me, { withReactionAndUserPairCache: true })).filter(note => !isMustRemove(note, 'home'));
await Promise.all(
packedNotes.map(note => removeMutedUsersReactions(note, userIdsWhoMeMuting)),
);

return packedNotes;
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
}
}
3 changes: 1 addition & 2 deletions packages/backend/src/core/entities/ChannelEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class ChannelEntityService {
src: MiChannel['id'] | MiChannel,
me?: { id: MiUser['id'] } | null | undefined,
detailed?: boolean,
pinnedNotesWithReactionAndUserPairCache?: boolean | false,
): Promise<Packed<'Channel'>> {
const channel = typeof src === 'object' ? src : await this.channelsRepository.findOneByOrFail({ id: src });
const meId = me ? me.id : null;
Expand Down Expand Up @@ -95,7 +94,7 @@ export class ChannelEntityService {
} : {}),

...(detailed ? {
pinnedNotes: (await this.noteEntityService.packMany(pinnedNotes, me, { withReactionAndUserPairCache: pinnedNotesWithReactionAndUserPairCache })).sort((a, b) => channel.pinnedNoteIds.indexOf(a.id) - channel.pinnedNoteIds.indexOf(b.id)),
pinnedNotes: (await this.noteEntityService.packMany(pinnedNotes, me)).sort((a, b) => channel.pinnedNoteIds.indexOf(a.id) - channel.pinnedNoteIds.indexOf(b.id)),
} : {}),
};
}
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ export class NoteEntityService implements OnModuleInit {
options?: {
detail?: boolean;
skipHide?: boolean;
withReactionAndUserPairCache?: boolean;
},
) {
if (notes.length === 0) return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ export class NoteFavoriteEntityService {
public async pack(
src: MiNoteFavorite['id'] | MiNoteFavorite,
me?: { id: MiUser['id'] } | null | undefined,
withReactionAndUserPairCache?: boolean,
) {
const favorite = typeof src === 'object' ? src : await this.noteFavoritesRepository.findOneByOrFail({ id: src });

return {
id: favorite.id,
createdAt: this.idService.parse(favorite.id).date.toISOString(),
noteId: favorite.noteId,
note: await this.noteEntityService.pack(favorite.note ?? favorite.noteId, me, { withReactionAndUserPairCache: withReactionAndUserPairCache }),
note: await this.noteEntityService.pack(favorite.note ?? favorite.noteId, me),
};
}

@bindThis
public packMany(
favorites: any[],
me: { id: MiUser['id'] },
withReactionAndUserPairCache?: boolean,
) {
return Promise.all(favorites.map(x => this.pack(x, me, withReactionAndUserPairCache)));
return Promise.all(favorites.map(x => this.pack(x, me)));
}
}
2 changes: 0 additions & 2 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ export class UserEntityService implements OnModuleInit {
userRelations?: Map<MiUser['id'], UserRelation>,
userMemos?: Map<MiUser['id'], string | null>,
pinNotes?: Map<MiUser['id'], MiUserNotePining[]>,
pinNotesWithReactionAndUserPairCache?: boolean,
},
): Promise<Packed<S>> {
const opts = Object.assign({
Expand Down Expand Up @@ -544,7 +543,6 @@ export class UserEntityService implements OnModuleInit {
pinnedNoteIds: pins.map(pin => pin.noteId),
pinnedNotes: this.noteEntityService.packMany(pins.map(pin => pin.note!), me, {
detail: true,
withReactionAndUserPairCache: opts.pinNotesWithReactionAndUserPairCache,
}),
pinnedPageId: profile!.pinnedPageId,
pinnedPage: profile!.pinnedPageId ? this.pageEntityService.pack(profile!.pinnedPageId, me) : null,
Expand Down
18 changes: 4 additions & 14 deletions packages/backend/src/core/hanamisearch/HanamiSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { bindThis } from '@/decorators.js';
import { Packed } from '@/misc/json-schema.js';
import { MiNote } from '@/models/Note.js';
import { MiUser } from '@/models/_.js';
import type { NotesRepository } from '@/models/_.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { CacheService } from '@/core/CacheService.js';
import { QueryService } from '@/core/QueryService.js';
import { IdService } from '@/core/IdService.js';
import { isMustRemove } from '@/misc/is-hidden-or-visibility-modified.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { removeMutedUsersReactions } from '@/misc/reactions-mute.js';
import type { Index, MeiliSearch } from 'meilisearch';

type K = string;
Expand Down Expand Up @@ -78,7 +75,6 @@ export class HanamiSearchService {
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,

private noteEntityService: NoteEntityService,
private cacheService: CacheService,
private idService: IdService,
) {
Expand Down Expand Up @@ -181,7 +177,7 @@ export class HanamiSearchService {
sinceId?: MiNote['id'];
limit?: number;
},
): Promise<Packed<'Note'>[]> {
): Promise<MiNote[]> {
const preferredMethod = opts.preferredMethod ?? 'hanamisearchv1';

if ((preferredMethod === 'hanamisearchv1' && this.hanamisearch)) {
Expand Down Expand Up @@ -209,7 +205,7 @@ export class HanamiSearchService {
limit?: number;
},
shouldTimeSeriesSort: boolean,
): Promise<Packed<'Note'>[]> {
): Promise<MiNote[]> {
const filter: Q = { op: 'and', qs: [] };

if (pagination.untilId) filter.qs.push({ op: '<', k: 'createdAt', v: this.idService.parse(pagination.untilId).date.getTime() });
Expand Down Expand Up @@ -246,12 +242,6 @@ export class HanamiSearchService {
return true;
});

notes.sort((a, b) => a.id > b.id ? -1 : 1);
const packedNotes = (await this.noteEntityService.packMany(notes, me, { withReactionAndUserPairCache: true })).filter(note => !isMustRemove(note, 'home'));
await Promise.all(
packedNotes.map(note => removeMutedUsersReactions(note, userIdsWhoMeMuting)),
);

return packedNotes;
return shouldTimeSeriesSort ? notes.sort((a, b) => (a.id > b.id ? -1 : 1)) : notes;
}
}
44 changes: 0 additions & 44 deletions packages/backend/src/misc/reactions-mute.ts

This file was deleted.

28 changes: 4 additions & 24 deletions packages/backend/src/server/api/endpoints/antennas/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { trackPromise } from '@/misc/promise-tracker.js';
import { isMustRemove } from '@/misc/is-hidden-or-visibility-modified.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { CacheService } from '@/core/CacheService.js';
import { removeMutedUsersReactions } from '@/misc/reactions-mute.js';
import { ApiError } from '../../error.js';

export const meta = {
Expand Down Expand Up @@ -72,7 +69,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.antennasRepository)
private antennasRepository: AntennasRepository,

private cacheService: CacheService,
private idService: IdService,
private noteEntityService: NoteEntityService,
private queryService: QueryService,
Expand Down Expand Up @@ -110,14 +106,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
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 query = this.notesRepository.createQueryBuilder('note')
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
.innerJoinAndSelect('note.user', 'user')
Expand All @@ -127,14 +115,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser');

this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);

const notes = (await query.getMany()).filter(note => {
if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
if (isUserRelated(note, userIdsWhoMeMuting)) return false;

return true;
});

const notes = await query.getMany();
if (sinceId != null && untilId == null) {
notes.sort((a, b) => a.id < b.id ? -1 : 1);
} else {
Expand All @@ -143,11 +127,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

this.noteReadService.read(me.id, notes);

const packedNotes = (await this.noteEntityService.packMany(notes, me, { withReactionAndUserPairCache: true })).filter(note => !isMustRemove(note, 'home'));
await Promise.all(
packedNotes.map(note => removeMutedUsersReactions(note, userIdsWhoMeMuting)),
);
return packedNotes;
return (await this.noteEntityService.packMany(notes, me)).filter(note => !isMustRemove(note, 'home'));
});
}
}
Loading

0 comments on commit 97b9a6b

Please sign in to comment.