Skip to content

Commit

Permalink
Feat: Exclude domains from blacklist sync (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Sep 13, 2023
1 parent 492df32 commit cdbd8a9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/services/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class DatabaseService {
filterByReasons: false,
reasonsFilter: [],
includeHesitations: false,
ignoreInstanceList: [],
ignoreInstances: false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ <h3 class="card-title">Synchronization</h3>
</select>
</ng-template>
</div>
<div class="form-group">
<div class="custom-control custom-switch custom-switch-on-danger">
<input class="custom-control-input" type="checkbox" id="inputIgnoreInstances" formControlName="ignoreInstances" aria-describedby="inputIgnoreInstancesDescription" />
<label for="inputIgnoreInstances" class="custom-control-label">Exclude instances from blacklist</label>
</div>
<small id="inputIgnoreInstancesDescription">
If enabled, you can specify a list of instances that will be excluded from blacklisting even if they match the other rules.
</small>
</div>
<div class="form-group position-relative" *ngIf="form.controls.filterByReasons.value">
<app-loader *ngIf="loadingWhitelistedInstances else instancesSelect" />
<ng-template #instancesSelect>
<select formControlName="ignoreInstanceList" tom-select multiple [create]="true" [maxItems]="null">
<option *ngFor="let option of whitelistedInstancesList" [value]="option.domain">{{option.domain}}</option>
</select>
</ng-template>
</div>
<div class="form-group">
<div class="custom-control custom-switch custom-switch-on-danger">
<input class="custom-control-input" type="checkbox" id="inputIncludeHesitations" formControlName="includeHesitations" aria-describedby="inputIncludeHesitationsDescription" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class SynchronizeLemmyComponent implements OnInit {
filterByReasons: new FormControl<boolean>(false),
reasonsFilter: new FormControl<string[]>([]),
includeHesitations: new FormControl<boolean>(false),
ignoreInstances: new FormControl<boolean>(false),
ignoreInstanceList: new FormControl<string[]>([]),
});

public loading = true;
Expand Down Expand Up @@ -75,6 +77,8 @@ export class SynchronizeLemmyComponent implements OnInit {
reasonsFilter: settings.reasonsFilter,
filterByReasons: settings.filterByReasons,
includeHesitations: settings.includeHesitations,
ignoreInstanceList: settings.ignoreInstanceList,
ignoreInstances: settings.ignoreInstances,
});

const instances = await this.getBlockedInstancesFromSource(this.authManager.currentInstanceSnapshot.name);
Expand All @@ -97,6 +101,8 @@ export class SynchronizeLemmyComponent implements OnInit {
filterByReasons: values.filterByReasons ?? false,
reasonsFilter: values.reasonsFilter ?? [],
includeHesitations: values.includeHesitations ?? false,
ignoreInstances: values.ignoreInstances ?? false,
ignoreInstanceList: values.ignoreInstanceList ?? [],
});
});
this.form.controls.mode.valueChanges.subscribe(mode => {
Expand Down Expand Up @@ -136,6 +142,20 @@ export class SynchronizeLemmyComponent implements OnInit {
}
this.loadDiffs(mode);
});
this.form.controls.ignoreInstances.valueChanges.subscribe(ignore => {
const mode = this.form.controls.mode.value;
if (ignore === null || mode === null) {
return;
}
this.loadDiffs(mode);
});
this.form.controls.ignoreInstanceList.valueChanges.subscribe(ignoreList => {
const mode = this.form.controls.mode.value;
if (ignoreList === null || mode === null) {
return;
}
this.loadDiffs(mode);
});
if (this.form.controls.mode.value) {
this.loadDiffs(this.form.controls.mode.value);
this.loadCustomInstancesSelect(this.form.controls.mode.value);
Expand Down Expand Up @@ -358,6 +378,9 @@ export class SynchronizeLemmyComponent implements OnInit {
if (this.form.controls.filterByReasons.value && this.form.controls.reasonsFilter.value) {
cacheKey += this.form.controls.reasonsFilter.value!.join('|');
}
if (this.form.controls.ignoreInstances.value && this.form.controls.ignoreInstanceList.value) {
cacheKey += this.form.controls.ignoreInstanceList.value!.join('|');
}
cacheKey += String(Number(this.form.controls.includeHesitations.value));

this.cache[myInstanceCacheKey] ??= await (async () => {
Expand Down Expand Up @@ -410,6 +433,11 @@ export class SynchronizeLemmyComponent implements OnInit {
).length,
);
}
if (this.form.controls.ignoreInstances.valid && this.form.controls.ignoreInstanceList.value) {
foreignInstanceBlacklist = foreignInstanceBlacklist.filter(
instance => !this.form.controls.ignoreInstanceList.value!.includes(instance.domain),
);
}
}

const result = [...this.cache[myInstanceCacheKey]!, ...foreignInstanceBlacklist];
Expand Down
4 changes: 3 additions & 1 deletion src/app/types/synchronize-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export interface SynchronizeSettings {
customInstances: string[];
filterByReasons: boolean;
reasonsFilter: string[];
includeHesitations: boolean,
includeHesitations: boolean;
ignoreInstances: boolean;
ignoreInstanceList: string[];
}

0 comments on commit cdbd8a9

Please sign in to comment.