Trigger sync only if the user has configured his account

This commit is contained in:
Vishnu Mohandas 2020-05-28 15:49:25 +05:30
parent 1c42e32adf
commit 9584f2ede7
3 changed files with 12 additions and 2 deletions

View file

@ -53,4 +53,8 @@ class Configuration {
void setPassword(String password) async {
await _preferences.setString(_passwordKey, password);
}
bool hasConfiguredAccount() {
return getEndpoint() != null && getToken() != null;
}
}

View file

@ -26,6 +26,9 @@ class FolderSharingService {
FolderSharingService._privateConstructor();
void sync() {
if (!Configuration.instance.hasConfiguredAccount()) {
return;
}
getFolders().then((f) async {
var folders = f.toSet();
var currentFolders = await FolderDB.instance.getFolders();

View file

@ -98,10 +98,13 @@ class PhotoSyncManager {
}
}
Future<void> _syncWithRemote(SharedPreferences prefs) {
_syncWithRemote(SharedPreferences prefs) {
// TODO: Fix race conditions triggered due to concurrent syncs.
// Add device_id/last_sync_timestamp to the upload request?
return _downloadDiff(prefs).then((_) {
if (!Configuration.instance.hasConfiguredAccount()) {
return;
}
_downloadDiff(prefs).then((_) {
_uploadDiff(prefs).then((_) {
_deletePhotosOnServer();
});