fetch followings asynchronously in bubble-timeline.ts
This commit is contained in:
@@ -76,7 +76,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
throw new ApiError(meta.errors.btlDisabled);
|
throw new ApiError(meta.errors.btlDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
const followings = me ? await this.cacheService.userFollowingsCache.fetch(me.id) : undefined;
|
// 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'),
|
||||||
@@ -122,16 +124,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
|
|
||||||
let timeline = await query.limit(ps.limit).getMany();
|
let timeline = await query.limit(ps.limit).getMany();
|
||||||
|
|
||||||
timeline = timeline.filter(note => {
|
const followings = await followingsPromise;
|
||||||
if (note.user?.isSilenced) {
|
if (me && followings) {
|
||||||
if (!me) return false;
|
timeline = timeline.filter(note => {
|
||||||
if (!followings) return false;
|
// Allow my own notes
|
||||||
if (note.userId !== me.id) {
|
if (note.userId === me.id) return true;
|
||||||
return followings[note.userId];
|
// Allow if not silenced
|
||||||
}
|
if (!note.user?.isSilenced) return true;
|
||||||
}
|
// Allow if following
|
||||||
return true;
|
return followings[note.userId];
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (me) {
|
if (me) {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user