deleteCalibreForever method

  1. @action
Future<ObservableList<CalibreWeebi<ArticleRawAbstract>>> deleteCalibreForever(
  1. CalibreWeebi<ArticleRawAbstract> calibreData
)

Implementation

@action
Future<ObservableList<CalibreWeebi>> deleteCalibreForever(
    CalibreWeebi calibreData) async {
  // checking on all existing articles if one is in the proxy
  // if the article being deleted is in a basket then remove it
  if (calibreData.isBasket == false && baskets.isNotEmpty) {
    try {
      await _propagateCalibreRetailDeletionInBaskets(calibreData.id);
    } catch (e) {
      print(
          '_propagateCalibreRetailDeletionInBaskets of ${calibreData.id} ${calibreData.title} failed because of $e\n delete it anyway');
    }
  }

  /// delete all calibre's photos
  if (photos.any((p) => p.calibreId == calibreData.id)) {
    // dart hack to copy a list
    final temp = [
      ...photos
          .where((p) => p.calibreId == calibreData.id)
          .map((e) => ArticlePhoto.fromMap(e.toMap()))
    ];
    for (final photo in temp) {
      await deletePhoto(photo, isLocalFileToBeDeleted: true);
    }
  }

  await _deleteCalibreServer(calibreData);

  await _articlesService.deleteCalibreForeverRpc.request(calibreData);
  final index = calibresFull.indexWhere((e) => e.id == calibreData.id);
  if (index != -1) {
    calibresFull.removeAt(index);
  }
  final indexC = _calibres.indexWhere((e) => e.id == calibreData.id);
  if (indexC != -1) {
    _calibres.removeAt(indexC);
  }

  return calibresFull;
}