replace silenced users check with generateSilencedUserQueryForNotes in bubble-timeline.ts

This commit is contained in:
Hazelnoot 2025-06-03 15:14:22 -04:00
parent 15ebb0ef85
commit 2258e439af

View file

@ -68,7 +68,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService, private queryService: QueryService,
private roleService: RoleService, private roleService: RoleService,
private activeUsersChart: ActiveUsersChart, private activeUsersChart: ActiveUsersChart,
private cacheService: CacheService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null); const policies = await this.roleService.getUserPolicies(me ? me.id : null);
@ -76,10 +75,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.btlDisabled); throw new ApiError(meta.errors.btlDisabled);
} }
// Run this asynchronously - we will await it after the query completes.
// Catch-suppression is needed to avoid "unhandled rejection" if the query throws.
const followingsPromise = me ? this.cacheService.userFollowingsCache.fetch(me.id).catch(() => null) : null;
//#region Construct query //#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
@ -92,6 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser'); .leftJoinAndSelect('renote.user', 'renoteUser');
this.queryService.generateBlockedHostQueryForNote(query); this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) { if (me) {
this.queryService.generateMutedUserQueryForNotes(query, me); this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me); this.queryService.generateBlockedUserQueryForNotes(query, me);
@ -122,19 +118,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
//#endregion //#endregion
let timeline = await query.limit(ps.limit).getMany(); const timeline = await query.limit(ps.limit).getMany();
const followings = await followingsPromise;
if (me && followings) {
timeline = timeline.filter(note => {
// Allow my own notes
if (note.userId === me.id) return true;
// Allow if not silenced
if (!note.user?.isSilenced) return true;
// Allow if following
return followings[note.userId];
});
}
if (me) { if (me) {
process.nextTick(() => { process.nextTick(() => {