fix: correzione filtro comunità al riavvio e priorità deduplicazione invertita

- Il background refresh al riavvio ora non riattiva il filtro comunità se comunitaEnabled è false nelle impostazioni, evitando di restringere silenziosamente il bacino dei canti.
- Invertita la logica di deduplicazione: in caso di canto duplicato (validato + non validato), ora vince la versione validata (ufficiale del catalogo).
This commit is contained in:
David Frassi
2026-05-20 16:09:30 +02:00
parent 98fc5e9c97
commit 8c9f9df11c
2 changed files with 11 additions and 3 deletions
+6 -3
View File
@@ -124,7 +124,9 @@ export class HomePage implements OnDestroy {
return comunitaIds.includes(c.id_canti) || comunitaIds.includes(c.id); return comunitaIds.includes(c.id_canti) || comunitaIds.includes(c.id);
}); });
// Deduplicate: if a song exists in both validated and unvalidated lists, keep only the unvalidated/custom one // Deduplicate: if a song exists in both validated and unvalidated lists,
// the NON-VALIDATED (parish-customized) version always takes precedence,
// so parishes can always personalize their songs even if never validated.
const seen = new Map<number | string, any>(); const seen = new Map<number | string, any>();
for (const canto of list) { for (const canto of list) {
const key = canto.id_canti || canto.id; const key = canto.id_canti || canto.id;
@@ -132,8 +134,9 @@ export class HomePage implements OnDestroy {
if (!existing) { if (!existing) {
seen.set(key, canto); seen.set(key, canto);
} else { } else {
// Precedence to unvalidated/custom version // Precedence to non-validated (parish custom) version:
if (canto.nonValidato) { // overwrite only if current entry is validated and new one is non-validated
if (!existing.nonValidato && canto.nonValidato) {
seen.set(key, canto); seen.set(key, canto);
} }
} }
+5
View File
@@ -60,7 +60,12 @@ export class ComunitaService {
if (savedCode) { if (savedCode) {
this.comunitaCode.set(savedCode); this.comunitaCode.set(savedCode);
// Run background refresh 1 second after startup to fetch any new custom canti or updates // Run background refresh 1 second after startup to fetch any new custom canti or updates
// but only if the community feature is enabled in settings
setTimeout(() => { setTimeout(() => {
if (!this.settingsService.comunitaEnabled()) {
// Community is disabled: skip refresh to avoid re-enabling the filter
return;
}
this.setComunitaCode(savedCode).catch(err => { this.setComunitaCode(savedCode).catch(err => {
console.warn('Failed background community refresh at startup:', err); console.warn('Failed background community refresh at startup:', err);
}); });