updateUserPreferences method
Updates user preferences for notifications.
Implementation
Future<NotificationFailure?> updateUserPreferences(
UserPreferencesModel preferences,
) async {
try {
_userPreferences = preferences.copyWith(lastUpdated: DateTime.now());
// Update both repositories' settings
final NotificationSettingsEntity settings = NotificationSettingsEntity(
isEnabled: preferences.globalNotificationsEnabled,
allowSound: preferences.soundEnabled,
allowVibration: preferences.vibrationEnabled,
allowBadge: preferences.badgeEnabled,
);
final NotificationFailure? localError = await _localRepository
.updateNotificationSettings(settings);
final NotificationFailure? firebaseError = await _firebaseRepository
.updateNotificationSettings(settings);
// Return the first error if any
return localError ?? firebaseError;
} catch (e, stackTrace) {
safeDebugLog('Failed to update user preferences: $e');
return NotificationFailure.configuration(
details: e.toString(),
stackTrace: stackTrace,
);
}
}