From 3857346e4851c07cf3c6c343d6268bf6742fb3fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:33:31 +0100 Subject: [PATCH 1/4] chore(deps): bump crop_image in /packages/smooth_app (#5825) Bumps [crop_image](https://github.com/deakjahn/crop_image) from 1.0.13 to 1.0.15. - [Changelog](https://github.com/deakjahn/crop_image/blob/master/CHANGELOG.md) - [Commits](https://github.com/deakjahn/crop_image/commits) --- updated-dependencies: - dependency-name: crop_image dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/smooth_app/pubspec.lock | 16 ++++++++-------- packages/smooth_app/pubspec.yaml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 631b8f973fe8..3ee61d55833b 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -305,10 +305,10 @@ packages: dependency: "direct main" description: name: crop_image - sha256: "6cf20655ecbfba99c369d43ec7adcfa49bf135af88fb75642173d6224a95d3f1" + sha256: "2e629cd141a360cb9060b5a0837fd49b0260d3d931244717213bf164f6813c82" url: "https://pub.dev" source: hosted - version: "1.0.13" + version: "1.0.15" cross_file: dependency: transitive description: @@ -696,10 +696,10 @@ packages: dependency: "direct main" description: name: flutter_svg - sha256: de82e6bf958cec7190fbc1c5298282c851228e35ae2b14e2b103e7f777818c64 + sha256: "578bd8c508144fdaffd4f77b8ef2d8c523602275cd697cc3db284dbd762ef4ce" url: "https://pub.dev" source: hosted - version: "2.0.13" + version: "2.0.14" flutter_test: dependency: "direct dev" description: flutter @@ -1703,10 +1703,10 @@ packages: dependency: transitive description: name: vector_graphics - sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3" + sha256: "773c9522d66d523e1c7b25dfb95cc91c26a1e17b107039cfe147285e92de7878" url: "https://pub.dev" source: hosted - version: "1.1.11+1" + version: "1.1.14" vector_graphics_codec: dependency: transitive description: @@ -1719,10 +1719,10 @@ packages: dependency: transitive description: name: vector_graphics_compiler - sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81" + sha256: "26d520739b7c6b5d2a2b3274427874a8390831fd4cd5bb8cfbd7d913477d3a2e" url: "https://pub.dev" source: hosted - version: "1.1.11+1" + version: "1.1.14" vector_math: dependency: transitive description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index 2971d80fb064..638dddc247fa 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -51,7 +51,7 @@ dependencies: flutter_native_splash: 2.4.2 image: 4.3.0 auto_size_text: 3.0.0 - crop_image: 1.0.13 + crop_image: 1.0.15 shared_preferences: 2.3.2 intl: 0.19.0 collection: 1.18.0 From 9100a8c0585b77452fc0eeca3dc052ad152699b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:39:18 +0100 Subject: [PATCH 2/4] chore(deps): bump sqflite from 2.4.0 to 2.4.1 in /packages/smooth_app (#5823) Bumps [sqflite](https://github.com/tekartik/sqflite) from 2.4.0 to 2.4.1. - [Commits](https://github.com/tekartik/sqflite/commits) --- updated-dependencies: - dependency-name: sqflite dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: monsieurtanuki --- packages/smooth_app/pubspec.lock | 8 ++++---- packages/smooth_app/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 3ee61d55833b..1aba445b8b05 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1487,10 +1487,10 @@ packages: dependency: "direct main" description: name: sqflite - sha256: "79a297dc3cc137e758c6a4baf83342b039e5a6d2436fcdf3f96a00adaaf2ad62" + sha256: "2d7299468485dca85efeeadf5d38986909c5eb0cd71fd3db2c2f000e6c9454bb" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.1" sqflite_android: dependency: transitive description: @@ -1519,10 +1519,10 @@ packages: dependency: transitive description: name: sqflite_darwin - sha256: "769733dddf94622d5541c73e4ddc6aa7b252d865285914b6fcd54a63c4b4f027" + sha256: "96a698e2bc82bd770a4d6aab00b42396a7c63d9e33513a56945cbccb594c2474" url: "https://pub.dev" source: hosted - version: "2.4.1-1" + version: "2.4.1" sqflite_platform_interface: dependency: transitive description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index 638dddc247fa..e94f476bcd75 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -38,7 +38,7 @@ dependencies: uuid: 4.5.1 provider: 6.1.2 sentry_flutter: 8.9.0 - sqflite: 2.4.0 + sqflite: 2.4.1 sqflite_common_ffi: 2.3.4 url_launcher: 6.3.0 visibility_detector: 0.4.0+2 From 431643285c8b957a3420d43311ff7ce1f63ae128 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:44:55 +0100 Subject: [PATCH 3/4] chore(deps): bump sentry_flutter in /packages/smooth_app (#5822) Bumps [sentry_flutter](https://github.com/getsentry/sentry-dart) from 8.9.0 to 8.10.1. - [Release notes](https://github.com/getsentry/sentry-dart/releases) - [Changelog](https://github.com/getsentry/sentry-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/getsentry/sentry-dart/compare/8.9.0...8.10.1) --- updated-dependencies: - dependency-name: sentry_flutter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: monsieurtanuki --- packages/smooth_app/pubspec.lock | 8 ++++---- packages/smooth_app/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 1aba445b8b05..39b25798d870 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1354,18 +1354,18 @@ packages: dependency: transitive description: name: sentry - sha256: "033287044a6644a93498969449d57c37907e56f5cedb17b88a3ff20a882261dd" + sha256: "2440763ae96fa8fd1bcdfc224f5232e1b7a09af76a72f4e626ee313a261faf6f" url: "https://pub.dev" source: hosted - version: "8.9.0" + version: "8.10.1" sentry_flutter: dependency: "direct main" description: name: sentry_flutter - sha256: "3780b5a0bb6afd476857cfbc6c7444d969c29a4d9bd1aa5b6960aa76c65b737a" + sha256: "3b30038b3b9303540a8b2c8b1c8f0bb93a207f8e4b25691c59d969ddeb4734fd" url: "https://pub.dev" source: hosted - version: "8.9.0" + version: "8.10.1" share_plus: dependency: "direct main" description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index e94f476bcd75..db5254800f54 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -37,7 +37,7 @@ dependencies: photo_view: 0.15.0 uuid: 4.5.1 provider: 6.1.2 - sentry_flutter: 8.9.0 + sentry_flutter: 8.10.1 sqflite: 2.4.1 sqflite_common_ffi: 2.3.4 url_launcher: 6.3.0 From 4d48671e3c47fb4638cce2e5ab15615571356b24 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Sat, 9 Nov 2024 22:52:04 +0100 Subject: [PATCH 4/4] feat: 5741 - respecting the "search products" access limitations (#5810) * feat: 5741 - respecting the "search products" access limitations New file: * `search_products_manager.dart`: Management of "search products" access limitations. Impacted files: * `background_task_download_products.dart`: refactored using `SearchProductsManager` * `background_task_language_refresh.dart`: refactored using `SearchProductsManager` * `background_task_top_barcodes.dart`: refactored using `SearchProductsManager` * `lazy_counter.dart`: refactored using `SearchProductsManager` * `paged_product_query.dart`: refactored using `SearchProductsManager` * `product_list_page.dart`: refactored using `SearchProductsManager` * `product_refresher.dart`: refactored using `SearchProductsManager` * `pubspec.lock`: wtf * fix: 5618 - category comparison for OxF Impacted files: * `background_task_language_refresh.dart`: explicitly setting the product_type * `dao_product.dart`: made `productType` mandatory and not null for `put` and `putAll` * `new_product_footer.dart`: fixed case with unexploitable `comparedToCategory` field * `product_list_page.dart`: explicitly setting the product_type * `product_refresher.dart`: explicitly setting the product_type * `pubspec.lock`: wtf * `query_product_list_supplier.dart`: explicitly setting the product_type * fix: 5617 - share link to correct Oxf server * fix: 5617 - share link to correct Oxf server Impacted files: * `app_en.arb`: added labels for sharing an Oxf product * `new_product_footer.dart`: now displaying a correct label for product sharing - in addition to correct url * `product_query.dart`: added labels for sharing an Oxf product * `pubspec.lock`: wtf * `pubspec.yaml`: downgraded sentry_flutter from problematic version --------- Co-authored-by: Edouard Marquez --- .../background_task_download_products.dart | 5 +- .../background_task_language_refresh.dart | 11 ++- .../background_task_top_barcodes.dart | 5 +- .../query_product_list_supplier.dart | 1 + .../smooth_app/lib/database/dao_product.dart | 10 ++- packages/smooth_app/lib/l10n/app_en.arb | 29 +++++++- .../lib/pages/preferences/lazy_counter.dart | 4 +- .../product/common/product_list_page.dart | 10 ++- .../product/common/product_refresher.dart | 11 ++- .../product_page/new_product_footer.dart | 25 ++++--- .../lib/query/paged_product_query.dart | 4 +- .../smooth_app/lib/query/product_query.dart | 19 ++++++ .../lib/query/search_products_manager.dart | 67 +++++++++++++++++++ packages/smooth_app/pubspec.lock | 12 ++-- packages/smooth_app/pubspec.yaml | 2 +- 15 files changed, 181 insertions(+), 34 deletions(-) create mode 100644 packages/smooth_app/lib/query/search_products_manager.dart diff --git a/packages/smooth_app/lib/background/background_task_download_products.dart b/packages/smooth_app/lib/background/background_task_download_products.dart index 0f5cf093497c..9a469d3aee0e 100644 --- a/packages/smooth_app/lib/background/background_task_download_products.dart +++ b/packages/smooth_app/lib/background/background_task_download_products.dart @@ -9,6 +9,7 @@ import 'package:smooth_app/database/dao_product.dart'; import 'package:smooth_app/database/dao_work_barcode.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; /// Background progressing task about downloading products. class BackgroundTaskDownloadProducts extends BackgroundTaskProgressing { @@ -123,7 +124,8 @@ class BackgroundTaskDownloadProducts extends BackgroundTaskProgressing { fields.remove(ProductField.KNOWLEDGE_PANELS); } final OpenFoodFactsLanguage language = ProductQuery.getLanguage(); - final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( + final SearchResult searchResult = + await SearchProductsManager.searchProducts( ProductQuery.getReadUser(), ProductSearchQueryConfiguration( fields: fields, @@ -137,6 +139,7 @@ class BackgroundTaskDownloadProducts extends BackgroundTaskProgressing { version: ProductQuery.productQueryVersion, ), uriHelper: uriProductHelper, + type: SearchProductsType.background, ); final List? downloadedProducts = searchResult.products; if (downloadedProducts == null) { diff --git a/packages/smooth_app/lib/background/background_task_language_refresh.dart b/packages/smooth_app/lib/background/background_task_language_refresh.dart index 4ef02070a7ef..2209b78cb6f6 100644 --- a/packages/smooth_app/lib/background/background_task_language_refresh.dart +++ b/packages/smooth_app/lib/background/background_task_language_refresh.dart @@ -7,6 +7,7 @@ import 'package:smooth_app/background/operation_type.dart'; import 'package:smooth_app/database/dao_product.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; /// Background task about downloading products to translate. class BackgroundTaskLanguageRefresh extends BackgroundTask { @@ -127,7 +128,8 @@ class BackgroundTaskLanguageRefresh extends BackgroundTask { if (barcodes.isEmpty) { return; } - final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( + final SearchResult searchResult = + await SearchProductsManager.searchProducts( getUser(), ProductSearchQueryConfiguration( fields: ProductQuery.fields, @@ -141,13 +143,18 @@ class BackgroundTaskLanguageRefresh extends BackgroundTask { version: ProductQuery.productQueryVersion, ), uriHelper: _uriProductHelper, + type: SearchProductsType.background, ); if (searchResult.products == null || searchResult.count == null) { throw Exception('Cannot refresh language'); } // save into database and refresh all visible products. - await daoProduct.putAll(searchResult.products!, language); + await daoProduct.putAll( + searchResult.products!, + language, + productType: productType, + ); localDatabase.upToDate.setLatestDownloadedProducts(searchResult.products!); // Next page diff --git a/packages/smooth_app/lib/background/background_task_top_barcodes.dart b/packages/smooth_app/lib/background/background_task_top_barcodes.dart index 383737df7c4c..40ccf4516210 100644 --- a/packages/smooth_app/lib/background/background_task_top_barcodes.dart +++ b/packages/smooth_app/lib/background/background_task_top_barcodes.dart @@ -9,6 +9,7 @@ import 'package:smooth_app/background/operation_type.dart'; import 'package:smooth_app/database/dao_work_barcode.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; /// Background progressing task about downloading top n barcodes. class BackgroundTaskTopBarcodes extends BackgroundTaskProgressing { @@ -101,7 +102,8 @@ class BackgroundTaskTopBarcodes extends BackgroundTaskProgressing { @override Future execute(final LocalDatabase localDatabase) async { - final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( + final SearchResult searchResult = + await SearchProductsManager.searchProducts( ProductQuery.getReadUser(), ProductSearchQueryConfiguration( fields: [ProductField.BARCODE], @@ -115,6 +117,7 @@ class BackgroundTaskTopBarcodes extends BackgroundTaskProgressing { version: ProductQuery.productQueryVersion, ), uriHelper: uriProductHelper, + type: SearchProductsType.background, ); if (searchResult.products == null || searchResult.count == null) { throw Exception('Cannot download top barcodes'); diff --git a/packages/smooth_app/lib/data_models/query_product_list_supplier.dart b/packages/smooth_app/lib/data_models/query_product_list_supplier.dart index c089faf0d4b1..3c3a8f4c3568 100644 --- a/packages/smooth_app/lib/data_models/query_product_list_supplier.dart +++ b/packages/smooth_app/lib/data_models/query_product_list_supplier.dart @@ -24,6 +24,7 @@ class QueryProductListSupplier extends ProductListSupplier { await DaoProduct(localDatabase).putAll( searchResult.products!, productQuery.language, + productType: productQuery.productType, ); } await DaoProductList(localDatabase).put(productList); diff --git a/packages/smooth_app/lib/database/dao_product.dart b/packages/smooth_app/lib/database/dao_product.dart index 1b677ae7ae9a..1b7fda44b94e 100644 --- a/packages/smooth_app/lib/database/dao_product.dart +++ b/packages/smooth_app/lib/database/dao_product.dart @@ -154,7 +154,7 @@ class DaoProduct extends AbstractSqlDao implements BulkDeletable { Future put( final Product product, final OpenFoodFactsLanguage language, { - final ProductType? productType, + required final ProductType productType, }) async => putAll( [product], @@ -166,12 +166,10 @@ class DaoProduct extends AbstractSqlDao implements BulkDeletable { Future putAll( final Iterable products, final OpenFoodFactsLanguage language, { - final ProductType? productType, + required final ProductType productType, }) async { - if (productType != null) { - for (final Product product in products) { - product.productType = productType; - } + for (final Product product in products) { + product.productType = productType; } await localDatabase.database.transaction( (final Transaction transaction) async => _bulkReplaceLoop( diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index c473f6d0ec03..8fb621c82eab 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -2311,7 +2311,34 @@ }, "share_product_text": "Have a look at this product on Open Food Facts: {url}", "@share_product_text": { - "description": "The content which is send, when sharing a product", + "description": "The content which is send, when sharing a 'food' product", + "placeholders": { + "url": { + "type": "String" + } + } + }, + "share_product_text_beauty": "Have a look at this product on Open Beauty Facts: {url}", + "@share_product_text_beauty": { + "description": "The content which is send, when sharing a 'beauty' product", + "placeholders": { + "url": { + "type": "String" + } + } + }, + "share_product_text_pet_food": "Have a look at this product on Open PetFood Facts: {url}", + "@share_product_text_pet_food": { + "description": "The content which is send, when sharing a 'pet food' product", + "placeholders": { + "url": { + "type": "String" + } + } + }, + "share_product_text_product": "Have a look at this product on Open Products Facts: {url}", + "@share_product_text_product": { + "description": "The content which is send, when sharing a 'products' product", "placeholders": { "url": { "type": "String" diff --git a/packages/smooth_app/lib/pages/preferences/lazy_counter.dart b/packages/smooth_app/lib/pages/preferences/lazy_counter.dart index 3d530e9cfa62..98bc9c778e17 100644 --- a/packages/smooth_app/lib/pages/preferences/lazy_counter.dart +++ b/packages/smooth_app/lib/pages/preferences/lazy_counter.dart @@ -3,6 +3,7 @@ import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/data_models/preferences/user_preferences.dart'; import 'package:smooth_app/query/paged_user_product_query.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; import 'package:smooth_app/services/smooth_services.dart'; /// Lazy Counter, with a cached value stored locally, and a call to the server. @@ -81,12 +82,13 @@ class LazyCounterUserSearch extends LazyCounter { ); try { - final SearchResult result = await OpenFoodAPIClient.searchProducts( + final SearchResult result = await SearchProductsManager.searchProducts( user, configuration, uriHelper: ProductQuery.getUriProductHelper( productType: ProductType.food, ), + type: SearchProductsType.count, ); return result.count; } catch (e) { diff --git a/packages/smooth_app/lib/pages/product/common/product_list_page.dart b/packages/smooth_app/lib/pages/product/common/product_list_page.dart index edf7293dec0d..e7577adb9336 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_page.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_page.dart @@ -31,6 +31,7 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart'; import 'package:smooth_app/pages/product_list_user_dialog_helper.dart'; import 'package:smooth_app/pages/scan/carousel/scan_carousel_manager.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; import 'package:smooth_app/resources/app_icons.dart' as icons; import 'package:smooth_app/themes/theme_provider.dart'; import 'package:smooth_app/widgets/smooth_app_bar.dart'; @@ -455,19 +456,24 @@ class _ProductListPageState extends State for (final MapEntry> entry in productTypes.entries) { final SearchResult searchResult = - await OpenFoodAPIClient.searchProducts( + await SearchProductsManager.searchProducts( ProductQuery.getReadUser(), ProductRefresher().getBarcodeListQueryConfiguration( entry.value, language, ), uriHelper: ProductQuery.getUriProductHelper(productType: entry.key), + type: SearchProductsType.live, ); final List? freshProducts = searchResult.products; if (freshProducts == null) { fresh = false; } else { - await DaoProduct(localDatabase).putAll(freshProducts, language); + await DaoProduct(localDatabase).putAll( + freshProducts, + language, + productType: entry.key, + ); localDatabase.upToDate.setLatestDownloadedProducts(freshProducts); } } diff --git a/packages/smooth_app/lib/pages/product/common/product_refresher.dart b/packages/smooth_app/lib/pages/product/common/product_refresher.dart index 664609e8ffe5..57e4883a04a5 100644 --- a/packages/smooth_app/lib/pages/product/common/product_refresher.dart +++ b/packages/smooth_app/lib/pages/product/common/product_refresher.dart @@ -13,6 +13,7 @@ import 'package:smooth_app/generic_lib/loading_dialog.dart'; import 'package:smooth_app/generic_lib/widgets/smooth_snackbar.dart'; import 'package:smooth_app/pages/user_management/login_page.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; import 'package:smooth_app/services/smooth_services.dart'; import 'package:smooth_app/themes/smooth_theme_colors.dart'; @@ -263,15 +264,21 @@ class ProductRefresher { ) async { try { final OpenFoodFactsLanguage language = ProductQuery.getLanguage(); - final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( + final SearchResult searchResult = + await SearchProductsManager.searchProducts( ProductQuery.getReadUser(), getBarcodeListQueryConfiguration(barcodes, language), uriHelper: ProductQuery.getUriProductHelper(productType: productType), + type: SearchProductsType.live, ); if (searchResult.products == null) { return null; } - await DaoProduct(localDatabase).putAll(searchResult.products!, language); + await DaoProduct(localDatabase).putAll( + searchResult.products!, + language, + productType: productType, + ); localDatabase.upToDate .setLatestDownloadedProducts(searchResult.products!); return searchResult.products!.length; diff --git a/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart b/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart index 0dc3e526ea1c..3715b582658d 100644 --- a/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart +++ b/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart @@ -227,22 +227,26 @@ class _ProductCompareButton extends StatelessWidget { tags.isNotEmpty && tags.length == labels.length) { categoryTag = product.comparedToCategory; - if (categoryTag == null || blackListedCategories.contains(categoryTag)) { + if (categoryTag != null) { + for (int i = 0; i < tags.length; i++) { + if (categoryTag == tags[i]) { + categoryLabel = labels[i]; + break; + } + } + } + if (categoryLabel == null || + blackListedCategories.contains(categoryTag)) { // fallback algorithm int index = tags.length - 1; // cf. https://github.com/openfoodfacts/openfoodfacts-dart/pull/474 // looking for the most detailed non blacklisted category categoryTag = tags[index]; + categoryLabel = labels[index]; while (blackListedCategories.contains(categoryTag) && index > 0) { index--; categoryTag = tags[index]; - } - } - if (categoryTag != null) { - for (int i = 0; i < tags.length; i++) { - if (categoryTag == tags[i]) { - categoryLabel = labels[i]; - } + categoryLabel = labels[index]; } } } @@ -329,6 +333,7 @@ class _ProductShareButton extends StatelessWidget { } Future _shareProduct(BuildContext context, Product product) async { + final ProductType productType = product.productType ?? ProductType.food; AnalyticsHelper.trackEvent( AnalyticsEvent.shareProduct, barcode: product.barcode, @@ -337,10 +342,10 @@ class _ProductShareButton extends StatelessWidget { // We need to provide a sharePositionOrigin to make the plugin work on ipad final RenderBox? box = context.findRenderObject() as RenderBox?; final String url = 'https://' - '${ProductQuery.getCountry().offTag}.openfoodfacts.org' + '${ProductQuery.getCountry().offTag}.${productType.getDomain()}.org' '/product/${product.barcode}'; Share.share( - appLocalizations.share_product_text(url), + productType.getShareProductLabel(appLocalizations, url), sharePositionOrigin: box == null ? null : box.localToGlobal(Offset.zero) & box.size, ); diff --git a/packages/smooth_app/lib/query/paged_product_query.dart b/packages/smooth_app/lib/query/paged_product_query.dart index 978a588f7ee2..e4dda790bf47 100644 --- a/packages/smooth_app/lib/query/paged_product_query.dart +++ b/packages/smooth_app/lib/query/paged_product_query.dart @@ -1,6 +1,7 @@ import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/data_models/product_list.dart'; import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/query/search_products_manager.dart'; /// Paged product query (with [pageSize] and [pageNumber]). abstract class PagedProductQuery { @@ -39,10 +40,11 @@ abstract class PagedProductQuery { void toTopPage() => _pageNumber = _startPageNumber; Future getSearchResult() async => - OpenFoodAPIClient.searchProducts( + SearchProductsManager.searchProducts( ProductQuery.getReadUser(), getQueryConfiguration(), uriHelper: ProductQuery.getUriProductHelper(productType: productType), + type: SearchProductsType.live, ); AbstractQueryConfiguration getQueryConfiguration(); diff --git a/packages/smooth_app/lib/query/product_query.dart b/packages/smooth_app/lib/query/product_query.dart index 76169110f7f6..8386ea5f22af 100644 --- a/packages/smooth_app/lib/query/product_query.dart +++ b/packages/smooth_app/lib/query/product_query.dart @@ -318,4 +318,23 @@ extension ProductTypeExtension on ProductType { ProductType.product => appLocalizations.hey_incomplete_product_message_product, }; + + String getShareProductLabel( + final AppLocalizations appLocalizations, + final String url, + ) => + switch (this) { + ProductType.food => appLocalizations.share_product_text( + url, + ), + ProductType.beauty => appLocalizations.share_product_text_beauty( + url, + ), + ProductType.petFood => appLocalizations.share_product_text_pet_food( + url, + ), + ProductType.product => appLocalizations.share_product_text_product( + url, + ), + }; } diff --git a/packages/smooth_app/lib/query/search_products_manager.dart b/packages/smooth_app/lib/query/search_products_manager.dart new file mode 100644 index 000000000000..ad64b48ee11f --- /dev/null +++ b/packages/smooth_app/lib/query/search_products_manager.dart @@ -0,0 +1,67 @@ +import 'package:openfoodfacts/openfoodfacts.dart'; + +/// Type of "search products" action. +enum SearchProductsType { + /// For heavy background tasks like offline downloads. + background, + + /// For live user interactions in the app. + live, + + /// For counts like "number of products I edited". + count; + + /// General threshold: 10 requests per minute. + static final TooManyRequestsManager _generalRequestManager = + TooManyRequestsManager( + maxCount: 10, + duration: const Duration(minutes: 1), + ); + + /// Specific threshold for background tasks. + static final TooManyRequestsManager _backgroundRequestManager = + TooManyRequestsManager( + maxCount: 3, + duration: const Duration(minutes: 1), + ); + + /// Specific threshold for count tasks. + /// + /// For the record there are currently 4 counts displayed. + static final TooManyRequestsManager _countRequestManager = + TooManyRequestsManager( + maxCount: 4, + duration: const Duration(minutes: 1), + ); + + Future _specificWaitIfNeeded() async => switch (this) { + SearchProductsType.background => + _backgroundRequestManager.waitIfNeeded(), + SearchProductsType.count => _countRequestManager.waitIfNeeded(), + SearchProductsType.live => null, + }; + + Future waitIfNeeded() async { + await _specificWaitIfNeeded(); + await _generalRequestManager.waitIfNeeded(); + } +} + +/// Management of "search products" access limitations. +class SearchProductsManager { + SearchProductsManager._(); + + static Future searchProducts( + final User? user, + final AbstractQueryConfiguration configuration, { + required final UriProductHelper uriHelper, + required final SearchProductsType type, + }) async { + await type.waitIfNeeded(); + return OpenFoodAPIClient.searchProducts( + user, + configuration, + uriHelper: uriHelper, + ); + } +} diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 39b25798d870..3cbc5bf41cb1 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1354,18 +1354,18 @@ packages: dependency: transitive description: name: sentry - sha256: "2440763ae96fa8fd1bcdfc224f5232e1b7a09af76a72f4e626ee313a261faf6f" + sha256: "033287044a6644a93498969449d57c37907e56f5cedb17b88a3ff20a882261dd" url: "https://pub.dev" source: hosted - version: "8.10.1" + version: "8.9.0" sentry_flutter: dependency: "direct main" description: name: sentry_flutter - sha256: "3b30038b3b9303540a8b2c8b1c8f0bb93a207f8e4b25691c59d969ddeb4734fd" + sha256: "3780b5a0bb6afd476857cfbc6c7444d969c29a4d9bd1aa5b6960aa76c65b737a" url: "https://pub.dev" source: hosted - version: "8.10.1" + version: "8.9.0" share_plus: dependency: "direct main" description: @@ -1719,10 +1719,10 @@ packages: dependency: transitive description: name: vector_graphics_compiler - sha256: "26d520739b7c6b5d2a2b3274427874a8390831fd4cd5bb8cfbd7d913477d3a2e" + sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1 url: "https://pub.dev" source: hosted - version: "1.1.14" + version: "1.1.15" vector_math: dependency: transitive description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index db5254800f54..e94f476bcd75 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -37,7 +37,7 @@ dependencies: photo_view: 0.15.0 uuid: 4.5.1 provider: 6.1.2 - sentry_flutter: 8.10.1 + sentry_flutter: 8.9.0 sqflite: 2.4.1 sqflite_common_ffi: 2.3.4 url_launcher: 6.3.0