feat: align iOS client safety and consent experience
This commit is contained in:
@@ -6,22 +6,18 @@ const aiConsentVersion = 'ai-data-consent-v1';
|
||||
|
||||
class AiConsentState {
|
||||
final bool isLoading;
|
||||
final bool isSaving;
|
||||
final bool granted;
|
||||
final String? userId;
|
||||
final String? error;
|
||||
|
||||
const AiConsentState({
|
||||
this.isLoading = true,
|
||||
this.isSaving = false,
|
||||
this.granted = false,
|
||||
this.userId,
|
||||
this.error,
|
||||
});
|
||||
|
||||
AiConsentState copyWith({bool? isLoading, bool? granted, String? userId}) {
|
||||
return AiConsentState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
granted: granted ?? this.granted,
|
||||
userId: userId ?? this.userId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final aiConsentProvider = NotifierProvider<AiConsentNotifier, AiConsentState>(
|
||||
@@ -36,21 +32,62 @@ class AiConsentNotifier extends Notifier<AiConsentState> {
|
||||
|
||||
Future<void> load(String userId) async {
|
||||
state = AiConsentState(isLoading: true, userId: userId);
|
||||
final value = await ref.read(localDbProvider).read(_key(userId));
|
||||
try {
|
||||
final value = await ref.read(localDbProvider).read(_key(userId));
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
granted: value == 'granted',
|
||||
userId: userId,
|
||||
);
|
||||
} catch (_) {
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
userId: userId,
|
||||
error: 'Authorization status could not be loaded.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> grant(String userId) async {
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
granted: value == 'granted',
|
||||
isSaving: true,
|
||||
granted: state.granted,
|
||||
userId: userId,
|
||||
);
|
||||
try {
|
||||
await ref.read(localDbProvider).write(_key(userId), 'granted');
|
||||
state = AiConsentState(isLoading: false, granted: true, userId: userId);
|
||||
return true;
|
||||
} catch (_) {
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
userId: userId,
|
||||
error: 'Authorization could not be saved.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> grant(String userId) async {
|
||||
await ref.read(localDbProvider).write(_key(userId), 'granted');
|
||||
state = AiConsentState(isLoading: false, granted: true, userId: userId);
|
||||
}
|
||||
|
||||
Future<void> revoke(String userId) async {
|
||||
await ref.read(localDbProvider).delete(_key(userId));
|
||||
state = AiConsentState(isLoading: false, granted: false, userId: userId);
|
||||
Future<bool> revoke(String userId) async {
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
isSaving: true,
|
||||
granted: state.granted,
|
||||
userId: userId,
|
||||
);
|
||||
try {
|
||||
await ref.read(localDbProvider).delete(_key(userId));
|
||||
state = AiConsentState(isLoading: false, granted: false, userId: userId);
|
||||
return true;
|
||||
} catch (_) {
|
||||
state = AiConsentState(
|
||||
isLoading: false,
|
||||
granted: true,
|
||||
userId: userId,
|
||||
error: 'Authorization could not be revoked.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user