nc-photos/app/lib/use_case/cache_favorite.dart

34 lines
1,002 B
Dart
Raw Normal View History

2022-01-25 11:08:13 +01:00
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/db/entity_converter.dart';
2022-01-25 11:08:13 +01:00
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/event/event.dart';
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2022-01-25 11:08:13 +01:00
2022-12-16 16:01:04 +01:00
part 'cache_favorite.g.dart';
@npLog
2022-01-25 11:08:13 +01:00
class CacheFavorite {
const CacheFavorite(this._c);
2022-01-25 11:08:13 +01:00
/// Cache favorites using results from remote
///
/// Return number of files updated
Future<int> call(Account account, Iterable<int> remoteFileIds) async {
_log.info("[call] Cache favorites");
final result = await _c.npDb.syncFavoriteFiles(
account: account.toDb(),
favoriteFileIds: remoteFileIds.toList(),
);
final count = result.insert + result.delete + result.update;
if (count > 0) {
KiwiContainer().resolve<EventBus>().fire(FavoriteResyncedEvent(account));
}
return count;
2022-01-25 11:08:13 +01:00
}
final DiContainer _c;
}