Add and remove from favorites silently

This commit is contained in:
Vishnu Mohandas 2020-12-04 04:00:10 +05:30
parent ae924a52ee
commit 7b721e596b
3 changed files with 16 additions and 23 deletions

View file

@ -264,7 +264,7 @@ class CollectionsService {
.then((value) async {
await _filesDB.insertMultiple(files);
Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
SyncService.instance.syncWithRemote();
SyncService.instance.syncWithRemote(silently: true);
});
}
@ -285,7 +285,7 @@ class CollectionsService {
);
await _filesDB.removeFromCollection(collectionID, params["fileIDs"]);
Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
SyncService.instance.syncWithRemote();
SyncService.instance.syncWithRemote(silently: true);
}
Future<Collection> createAndCacheCollection(Collection collection) async {

View file

@ -175,12 +175,12 @@ class SyncService {
await _prefs.setInt(_dbUpdationTimeKey, toTime);
}
Future<void> syncWithRemote() async {
Future<void> syncWithRemote({bool silently = false}) async {
if (!Configuration.instance.hasConfiguredAccount()) {
return Future.error("Account not configured yet");
}
final updatedCollections = await _collectionsService.sync();
if (updatedCollections.isNotEmpty) {
if (updatedCollections.isNotEmpty && !silently) {
Bus.instance.fire(SyncStatusUpdate(SyncStatus.applying_remote_diff));
}
for (final collection in updatedCollections) {
@ -189,10 +189,7 @@ class SyncService {
await deleteFilesOnServer();
bool hasUploadedFiles = await _uploadDiff();
if (hasUploadedFiles) {
final updatedCollections = await _collectionsService.sync();
for (final collection in updatedCollections) {
await _fetchEncryptedFilesDiff(collection.id);
}
syncWithRemote(silently: true);
}
}

View file

@ -196,34 +196,30 @@ class _DetailPageState extends State<DetailPage> {
final isLiked = !oldValue;
bool hasError = false;
if (isLiked) {
final dialog =
createProgressDialog(context, "Adding to favorites...");
await dialog.show();
final shouldBlockUser = file.uploadedFileID == null;
var dialog;
if (shouldBlockUser) {
dialog = createProgressDialog(context, "Adding to favorites...");
await dialog.show();
}
try {
await FavoritesService.instance.addToFavorites(file);
showToast("Added to favorites.");
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
hasError = true;
showGenericErrorDialog(context);
showToast("Sorry, could not add this to favorites!");
} finally {
await dialog.hide();
if (shouldBlockUser) {
await dialog.hide();
}
}
} else {
final dialog =
createProgressDialog(context, "Removing from favorites...");
await dialog.show();
try {
await FavoritesService.instance.removeFromFavorites(file);
showToast("Removed from favorites.");
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
hasError = true;
showGenericErrorDialog(context);
} finally {
await dialog.hide();
showToast("Sorry, could not remove this from favorites!");
}
}
return hasError ? oldValue : isLiked;