From 7de845fd39ea76cce8c18bcc43840e1c7092cc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Chr=C3=A1steck=C3=BD?= Date: Tue, 12 Sep 2023 17:33:46 +0200 Subject: [PATCH] Fix: Undefined error when using own mode for sync (#8) --- .../synchronize-lemmy.component.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/censures/pages/synchronize-lemmy/synchronize-lemmy.component.ts b/src/app/censures/pages/synchronize-lemmy/synchronize-lemmy.component.ts index 8243c78..dc725ca 100644 --- a/src/app/censures/pages/synchronize-lemmy/synchronize-lemmy.component.ts +++ b/src/app/censures/pages/synchronize-lemmy/synchronize-lemmy.component.ts @@ -356,17 +356,19 @@ export class SynchronizeLemmyComponent implements OnInit { throw new Error(`Unsupported mode: ${mode}`); } - let foreignInstanceBlacklist = await this.getCensuresByInstances(sourceFrom) ?? []; - if (this.form.controls.filterByReasons.value && this.form.controls.reasonsFilter.value) { - const reasons = this.form.controls.reasonsFilter.value!; - foreignInstanceBlacklist = foreignInstanceBlacklist.filter( - instance => NormalizedInstanceDetailResponse.fromInstanceDetail(instance).unmergedCensureReasons.filter( - reason => reasons.includes(reason), - ).length, - ); + let foreignInstanceBlacklist: InstanceDetailResponse[] = []; + if (sourceFrom.length) { + foreignInstanceBlacklist = await this.getCensuresByInstances(sourceFrom) ?? []; + if (this.form.controls.filterByReasons.value && this.form.controls.reasonsFilter.value) { + const reasons = this.form.controls.reasonsFilter.value!; + foreignInstanceBlacklist = foreignInstanceBlacklist.filter( + instance => NormalizedInstanceDetailResponse.fromInstanceDetail(instance).unmergedCensureReasons.filter( + reason => reasons.includes(reason), + ).length, + ); + } } - return [...this.cache[myInstance]!, ...foreignInstanceBlacklist]; })();