diff --git a/lib/src/objects/parse_base.dart b/lib/src/objects/parse_base.dart index 795f06391..424c3ee7a 100644 --- a/lib/src/objects/parse_base.dart +++ b/lib/src/objects/parse_base.dart @@ -45,6 +45,7 @@ abstract class ParseBase { if (value is ParseObject && value._areChildrenDirty(seenObjects)) { return true; } + return false; }); return false; } @@ -175,8 +176,7 @@ abstract class ParseBase { /// Saves in storage Future saveInStorage(String key) async { final String objectJson = json.encode(toJson(full: true)); - ParseCoreData().getStore() - ..setString(key, objectJson); + await ParseCoreData().getStore().setString(key, objectJson); } /// Sets type [T] from objectData @@ -240,8 +240,7 @@ abstract class ParseBase { await unpin(); final Map objectMap = parseEncode(this, full: true); final String json = jsonEncode(objectMap); - ParseCoreData().getStore() - ..setString(objectId, json); + await ParseCoreData().getStore().setString(objectId, json); return true; } else { return false; @@ -253,8 +252,7 @@ abstract class ParseBase { /// Replicates Android SDK pin process and saves object to storage Future unpin({String key}) async { if (objectId != null) { - ParseCoreData().getStore() - ..remove(key ?? objectId); + await ParseCoreData().getStore().remove(key ?? objectId); return true; } diff --git a/lib/src/objects/parse_installation.dart b/lib/src/objects/parse_installation.dart index dfec33f27..0f3a66145 100644 --- a/lib/src/objects/parse_installation.dart +++ b/lib/src/objects/parse_installation.dart @@ -127,7 +127,7 @@ class ParseInstallation extends ParseObject { /// Gets the locally stored installation static Future _getFromLocalStore() async { - final CoreStore coreStore = await ParseCoreData().getStore(); + final CoreStore coreStore = ParseCoreData().getStore(); final String installationJson = await coreStore.getString(keyParseStoreInstallation); @@ -204,17 +204,17 @@ class ParseInstallation extends ParseObject { } ///Subscribes the device to a channel of push notifications. - void subscribeToChannel(String value) { + Future subscribeToChannel(String value) async { final List channel = [value]; setAddAllUnique('channels', channel); - save(); + await save(); } ///Unsubscribes the device to a channel of push notifications. - void unsubscribeFromChannel(String value) { + Future unsubscribeFromChannel(String value) async { final List channel = [value]; setRemove('channels', channel); - save(); + await save(); } ///Returns an > containing all the channel names this device is subscribed to. diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart index f2b99e2f5..05d574e48 100644 --- a/lib/src/objects/parse_user.dart +++ b/lib/src/objects/parse_user.dart @@ -100,7 +100,7 @@ class ParseUser extends ParseObject implements ParseCloneable { try { final Uri url = getSanitisedUri(_client, '$keyEndPointUserName'); final Response response = await _client.get(url, headers: headers); - return _handleResponse(_getEmptyUser(), response, ParseApiRQ.currentUser, + return await _handleResponse(_getEmptyUser(), response, ParseApiRQ.currentUser, _debug, _getEmptyUser().parseClassName); } on Exception catch (e) { return handleException( @@ -144,7 +144,7 @@ class ParseUser extends ParseObject implements ParseCloneable { }, body: body); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.signUp, _debug, parseClassName); } on Exception catch (e) { return handleException(e, ParseApiRQ.signUp, _debug, parseClassName); @@ -170,7 +170,7 @@ class ParseUser extends ParseObject implements ParseCloneable { keyHeaderRevocableSession: '1', }); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.login, _debug, parseClassName); } on Exception catch (e) { return handleException(e, ParseApiRQ.login, _debug, parseClassName); @@ -193,7 +193,7 @@ class ParseUser extends ParseObject implements ParseCloneable { } })); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.loginAnonymous, _debug, parseClassName); } on Exception catch (e) { return handleException( @@ -220,7 +220,7 @@ class ParseUser extends ParseObject implements ParseCloneable { 'authData': {provider: authData} })); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.loginWith, _debug, parseClassName); } on Exception catch (e) { return handleException(e, ParseApiRQ.loginWith, _debug, parseClassName); @@ -246,7 +246,7 @@ class ParseUser extends ParseObject implements ParseCloneable { final Response response = await _client.post(url, headers: {keyHeaderSessionToken: sessionId}); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.logout, _debug, parseClassName); } on Exception catch (e) { return handleException(e, ParseApiRQ.logout, _debug, parseClassName); @@ -259,7 +259,7 @@ class ParseUser extends ParseObject implements ParseCloneable { final Response response = await _client.post( '${_client.data.serverUrl}$keyEndPointVerificationEmail', body: json.encode({keyVarEmail: emailAddress})); - return _handleResponse(this, response, + return await _handleResponse(this, response, ParseApiRQ.verificationEmailRequest, _debug, parseClassName); } on Exception catch (e) { return handleException( @@ -273,7 +273,7 @@ class ParseUser extends ParseObject implements ParseCloneable { final Response response = await _client.post( '${_client.data.serverUrl}$keyEndPointRequestPasswordReset', body: json.encode({keyVarEmail: emailAddress})); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.requestPasswordReset, _debug, parseClassName); } on Exception catch (e) { @@ -289,19 +289,27 @@ class ParseUser extends ParseObject implements ParseCloneable { @override Future save() async { if (objectId == null) { - return signUp(); + return await signUp(); } else { - return super.save(); + final ParseResponse response = await super.save(); + if (response.success) { + await _onResponseSuccess(); + } + return response; } } + Future _onResponseSuccess() async { + await saveInStorage(keyParseStoreUser); + } + /// Removes a user from Parse Server locally and online Future destroy() async { if (objectId != null) { try { final Uri url = getSanitisedUri(_client, '$_path/$objectId'); final Response response = await _client.delete(url); - return _handleResponse( + return await _handleResponse( this, response, ParseApiRQ.destroy, _debug, parseClassName); } on Exception catch (e) { return handleException(e, ParseApiRQ.destroy, _debug, parseClassName); @@ -334,7 +342,7 @@ class ParseUser extends ParseObject implements ParseCloneable { static Future _getUserFromLocalStore( {ParseCloneable cloneable}) async { - final CoreStore coreStore = await ParseCoreData().getStore(); + final CoreStore coreStore = ParseCoreData().getStore(); final String userJson = await coreStore.getString(keyParseStoreUser); if (userJson != null) { @@ -351,8 +359,8 @@ class ParseUser extends ParseObject implements ParseCloneable { } /// Handles all the response data for this class - static ParseResponse _handleResponse(ParseUser user, Response response, - ParseApiRQ type, bool debug, String className) { + static Future _handleResponse(ParseUser user, Response response, + ParseApiRQ type, bool debug, String className) async { final ParseResponse parseResponse = handleResponse(user, response, type, debug, className); @@ -371,7 +379,7 @@ class ParseUser extends ParseObject implements ParseCloneable { return parseResponse; } else { final ParseUser user = parseResponse.result; - user?.saveInStorage(keyParseStoreUser); + await user?._onResponseSuccess(); return parseResponse; } }