wip: optimizations

This commit is contained in:
2026-05-23 15:28:40 +02:00
parent 5bf506af03
commit 155fe20862
89 changed files with 7431 additions and 392 deletions

View File

@@ -1,36 +1,36 @@
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { STORAGE_KEY_NOTIFICATION_SETTINGS } from '../../../../core/constants';
import { jsonStorage } from '../../../../infrastructure/persistence/json-storage.service';
import { createDefaultNotificationSettings, type NotificationsSettings } from '../../domain/models/notification.model';
@Injectable({ providedIn: 'root' })
export class NotificationSettingsStorageService {
private readonly storage = jsonStorage;
load(): NotificationsSettings {
const fallback = createDefaultNotificationSettings();
const raw = localStorage.getItem(STORAGE_KEY_NOTIFICATION_SETTINGS);
const parsed = this.storage.read<Partial<NotificationsSettings> | null>(
STORAGE_KEY_NOTIFICATION_SETTINGS,
null
);
if (!raw) {
if (!parsed) {
return fallback;
}
try {
const parsed = JSON.parse(raw) as Partial<NotificationsSettings>;
return {
enabled: parsed.enabled ?? fallback.enabled,
showPreview: parsed.showPreview ?? fallback.showPreview,
respectBusyStatus: parsed.respectBusyStatus ?? fallback.respectBusyStatus,
mutedRooms: normaliseBooleanRecord(parsed.mutedRooms),
mutedChannels: normaliseNestedBooleanRecord(parsed.mutedChannels),
roomBaselines: normaliseNumberRecord(parsed.roomBaselines),
lastReadByChannel: normaliseNestedNumberRecord(parsed.lastReadByChannel)
};
} catch {
return fallback;
}
return {
enabled: parsed.enabled ?? fallback.enabled,
showPreview: parsed.showPreview ?? fallback.showPreview,
respectBusyStatus: parsed.respectBusyStatus ?? fallback.respectBusyStatus,
mutedRooms: normaliseBooleanRecord(parsed.mutedRooms),
mutedChannels: normaliseNestedBooleanRecord(parsed.mutedChannels),
roomBaselines: normaliseNumberRecord(parsed.roomBaselines),
lastReadByChannel: normaliseNestedNumberRecord(parsed.lastReadByChannel)
};
}
save(settings: NotificationsSettings): void {
localStorage.setItem(STORAGE_KEY_NOTIFICATION_SETTINGS, JSON.stringify(settings));
this.storage.write(STORAGE_KEY_NOTIFICATION_SETTINGS, settings);
}
}