Files
smooth-app/packages/smooth_app/lib/query/random_questions_query.dart
monsieurtanuki cb815b0cac feat: 4020 - instant answers for hunger games (#4099)
* feat: 4020 - instant answers for hunger games

New files:
* `background_task_hunger_games.dart`: Background task about answering a hunger games question.
* `random_questions_query.dart`: Robotoff questions helper, for random product questions.

Deleted file:
* `product_question_page.dart`

Impacted files:
* `abstract_background_task.dart`: added "hunger games"
* `background_task_crop.dart`: minor refactoring
* `background_task_details.dart`: minor refactoring
* `background_task_image.dart`: minor refactoring
* `background_task_manager.dart`: simplified the code, as we now always work on tasks with different stamps
* `background_task_refresh.dart`: minor refactoring
* `background_task_unselect.dart`: minor refactoring
* `new_product_page.dart`: minor refactoring
* `offline_data_page.dart`: minor refactoring
* `operation_type.dart`: added a type for "hunger games" background task
* `product_list_import_export.dart`: minor refactoring
* `product_list_page.dart`: minor refactoring
* `product_questions_query.dart`: pre-loads the product if relevant
* `product_questions_widget.dart`: minor refactoring
* `product_refresher.dart`: new standard configuration for product lists; new silent download of product lists; minor refactoring
* `question_card.dart`: now downloading the product only if not in the local database
* `question_page.dart`: now saving the answer with background tasks; refactored
* `questions_query.dart`: refactored as abstract, with code moved to new file `random_questions_query.dart`
* `robotoff_insight_helper.dart`: minor refactoring

* feat: 4020 - unrelated package upgrade

* fix: 4098 - new enum value from iOS 12
2023-06-08 18:13:48 +02:00

37 lines
1.2 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,
) async {
final RobotoffQuestionResult result =
await RobotoffAPIClient.getRandomQuestions(
ProductQuery.getLanguage(),
OpenFoodAPIConfiguration.globalUser,
count: 3,
// TODO(monsieurtanuki): should use Country too
);
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>[];
}
}