Files
smooth-app/packages/smooth_app/lib/query/random_questions_query.dart
monsieurtanuki 7a81c0c69f feat: 5014 - track all READ server queries when consented (#5057)
* feat: 5014 - track all READ server queries when consented

Impacted files:
* `analytics_helper.dart`: added a public static `isEnabled` method
* `background_task.dart`: now explicitly using the WRITE user
* `background_task_download_products.dart`: now explicitly using the READ user
* `background_task_top_barcodes.dart`: now explicitly using the READ user
* `brand_suggestion_manager.dart`: now explicitly using the READ user
* `ocr_helper.dart`: now explicitly using the READ user
* `paged_product_query.dart`: now explicitly using the READ user
* `product_list_page.dart`: now explicitly using the READ user
* `product_query.dart`: split the user into READ and WRITE users
* `product_refresher.dart`: now explicitly using the READ user
* `random_questions_query.dart`: now explicitly using the READ user
* `simple_input_text_field.dart`: now explicitly using the READ user
* `user_management_provider.dart`: now explicitly using the WRITE user
* `user_preferences_account.dart`: now explicitly using the WRITE user

* minor refactoring

* merge conflicts desperate fix
2024-02-13 20:24:26 +01:00

38 lines
1.3 KiB
Dart

import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/query/questions_query.dart';
/// Robotoff questions helper, for random product questions.
class RandomQuestionsQuery extends QuestionsQuery {
@override
Future<List<RobotoffQuestion>> getQuestions(
final LocalDatabase localDatabase,
final int count,
) async {
final RobotoffQuestionResult result = await RobotoffAPIClient.getQuestions(
ProductQuery.getLanguage(),
user: ProductQuery.getReadUser(),
countries: <OpenFoodFactsCountry>[ProductQuery.getCountry()],
count: count,
questionOrder: RobotoffQuestionOrder.random,
);
if (result.questions?.isNotEmpty != true) {
return <RobotoffQuestion>[];
}
final List<String> barcodes = <String>[];
for (final RobotoffQuestion question in result.questions!) {
if (question.barcode != null) {
barcodes.add(question.barcode!);
}
}
await ProductRefresher().silentFetchAndRefreshList(
barcodes: barcodes,
localDatabase: localDatabase,
);
return result.questions ?? <RobotoffQuestion>[];
}
}