Managed mode: satisfy the strict, loop and test ratchets

- enabledPhotoProviderIds skips rows without an id instead of widening the type.
- The listed events read each addon once, in parallel, not in a loop.
- The narrowing test reuses the suite's service and swaps the addon answers.
- PlaceContribPanel keeps its complexity by naming the standalone check.
This commit is contained in:
Maurice
2026-11-02 22:46:14 +01:00
committed by Maurice
parent 86513fda0d
commit 59e68d81b2
5 changed files with 192 additions and 41 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ export class AddonsService {
/** The photo providers users can connect: none while the journey addon is off. */
async enabledPhotoProviderIds(): Promise<string[]> {
if (!(await this.isAddonEnabled(ADDON_IDS.JOURNEY))) return [];
return (await this.photoProviders.listEnabled()).map((row) => row.id);
return (await this.photoProviders.listEnabled()).flatMap((row) => (row.id ? [row.id] : []));
}
/** wanderer may be used: Tours is on and the admin allowed it under Tours. */
@@ -97,16 +97,15 @@ export class NotificationPreferencesService {
*/
private async listedEventTypes(): Promise<NotifEventType[]> {
const photoProviders = await this.addons.enabledPhotoProviderIds();
const addonOn = new Map<string, boolean>();
const on = async (id: string) => {
if (!addonOn.has(id)) addonOn.set(id, await this.addons.isAddonEnabled(id));
return addonOn.get(id) === true;
// One read per addon, shared by the events that hang off it.
const addonOn = new Map<string, Promise<boolean>>();
const on = (id: string): Promise<boolean> => {
if (!addonOn.has(id)) addonOn.set(id, this.addons.isAddonEnabled(id));
return addonOn.get(id) as Promise<boolean>;
};
const listed: NotifEventType[] = [];
for (const event of offeredEventTypes()) {
if (await this.featureOn(event, on, photoProviders)) listed.push(event);
}
return listed;
const events = offeredEventTypes();
const shown = await Promise.all(events.map((event) => this.featureOn(event, on, photoProviders)));
return events.filter((_, i) => shown[i]);
}
private async featureOn(