From dbbc5e830bbded10936bab3ae7f76030316a7553 Mon Sep 17 00:00:00 2001 From: Oleksandr Matsko Date: Sat, 10 Aug 2019 08:15:38 +0200 Subject: [PATCH 1/4] Updated dependencies. --- example/pubspec.yaml | 2 +- pubspec.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 31b0596b5..620f1db5f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 - sembast: ^1.13.3+1 + sembast: ^2.0.1 shared_preferences: ^0.5.0 dev_dependencies: diff --git a/pubspec.yaml b/pubspec.yaml index 1223c4559..9db986eb3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,19 +10,19 @@ environment: dependencies: flutter: sdk: flutter - + # Networking web_socket_channel: ^1.0.9 http: ^0.12.0 #Database - sembast: ^1.15.1 + sembast: ^2.0.1 xxtea: ^2.0.2 shared_preferences: ^0.5.2 # Utils - path_provider: ^0.5.0+1 + path_provider: ^1.2.0 uuid: ^2.0.0 package_info: ^0.4.0 devicelocale: ^0.1.1 From 17e9db829fe22f2526b1e8ac700de6d4c4ee2ccb Mon Sep 17 00:00:00 2001 From: Oleksandr Matsko Date: Sat, 10 Aug 2019 12:01:44 +0200 Subject: [PATCH 2/4] ParseUser._handleResponse was calling saveInStorage() async without an await, which caused 'invalid session token' error if user ParseUser.currentUser() immediately after ParseUser.signUp() or ParseUser.login(). Added missing awaits in other places. --- lib/src/objects/parse_base.dart | 10 ++++----- lib/src/objects/parse_installation.dart | 10 ++++----- lib/src/objects/parse_user.dart | 30 ++++++++++++------------- 3 files changed, 24 insertions(+), 26 deletions(-) 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..f0f93c00f 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,9 +289,9 @@ class ParseUser extends ParseObject implements ParseCloneable { @override Future save() async { if (objectId == null) { - return signUp(); + return await signUp(); } else { - return super.save(); + return await super.save(); } } @@ -301,7 +301,7 @@ class ParseUser extends ParseObject implements ParseCloneable { 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 +334,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 +351,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 +371,7 @@ class ParseUser extends ParseObject implements ParseCloneable { return parseResponse; } else { final ParseUser user = parseResponse.result; - user?.saveInStorage(keyParseStoreUser); + await user?.saveInStorage(keyParseStoreUser); return parseResponse; } } From f6834c1c78b5db7025c47be363b6596b3d6a4c0a Mon Sep 17 00:00:00 2001 From: Oleksandr Matsko Date: Sat, 10 Aug 2019 12:18:53 +0200 Subject: [PATCH 3/4] ParseUser was not updated in storage after a successful save() operation. Reason: no safeInStorage() after save() was called. Fix: calling saveInStorage() after save(). --- lib/src/objects/parse_user.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart index f0f93c00f..05d574e48 100644 --- a/lib/src/objects/parse_user.dart +++ b/lib/src/objects/parse_user.dart @@ -291,10 +291,18 @@ class ParseUser extends ParseObject implements ParseCloneable { if (objectId == null) { return await signUp(); } else { - return await 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) { @@ -371,7 +379,7 @@ class ParseUser extends ParseObject implements ParseCloneable { return parseResponse; } else { final ParseUser user = parseResponse.result; - await user?.saveInStorage(keyParseStoreUser); + await user?._onResponseSuccess(); return parseResponse; } } From 776a3956758f8df4508726f8e033dfce6e148412 Mon Sep 17 00:00:00 2001 From: Oleksandr Matsko Date: Sat, 10 Aug 2019 12:56:57 +0200 Subject: [PATCH 4/4] Revert "Updated dependencies." This reverts commit dbbc5e830bbded10936bab3ae7f76030316a7553. --- example/pubspec.yaml | 2 +- pubspec.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 620f1db5f..31b0596b5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 - sembast: ^2.0.1 + sembast: ^1.13.3+1 shared_preferences: ^0.5.0 dev_dependencies: diff --git a/pubspec.yaml b/pubspec.yaml index 9db986eb3..1223c4559 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,19 +10,19 @@ environment: dependencies: flutter: sdk: flutter - + # Networking web_socket_channel: ^1.0.9 http: ^0.12.0 #Database - sembast: ^2.0.1 + sembast: ^1.15.1 xxtea: ^2.0.2 shared_preferences: ^0.5.2 # Utils - path_provider: ^1.2.0 + path_provider: ^0.5.0+1 uuid: ^2.0.0 package_info: ^0.4.0 devicelocale: ^0.1.1