Skip to content

Added some missing async/await #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/src/objects/parse_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class ParseBase {
if (value is ParseObject && value._areChildrenDirty(seenObjects)) {
return true;
}
return false;
});
return false;
}
Expand Down Expand Up @@ -175,8 +176,7 @@ abstract class ParseBase {
/// Saves in storage
Future<void> 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
Expand Down Expand Up @@ -240,8 +240,7 @@ abstract class ParseBase {
await unpin();
final Map<String, dynamic> 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;
Expand All @@ -253,8 +252,7 @@ abstract class ParseBase {
/// Replicates Android SDK pin process and saves object to storage
Future<bool> unpin({String key}) async {
if (objectId != null) {
ParseCoreData().getStore()
..remove(key ?? objectId);
await ParseCoreData().getStore().remove(key ?? objectId);
return true;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/objects/parse_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ParseInstallation extends ParseObject {

/// Gets the locally stored installation
static Future<ParseInstallation> _getFromLocalStore() async {
final CoreStore coreStore = await ParseCoreData().getStore();
final CoreStore coreStore = ParseCoreData().getStore();

final String installationJson =
await coreStore.getString(keyParseStoreInstallation);
Expand Down Expand Up @@ -204,17 +204,17 @@ class ParseInstallation extends ParseObject {
}

///Subscribes the device to a channel of push notifications.
void subscribeToChannel(String value) {
Future<void> subscribeToChannel(String value) async {
final List<dynamic> channel = <String>[value];
setAddAllUnique('channels', channel);
save();
await save();
}

///Unsubscribes the device to a channel of push notifications.
void unsubscribeFromChannel(String value) {
Future<void> unsubscribeFromChannel(String value) async {
final List<dynamic> channel = <String>[value];
setRemove('channels', channel);
save();
await save();
}

///Returns an <List<String>> containing all the channel names this device is subscribed to.
Expand Down
38 changes: 23 additions & 15 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -220,7 +220,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
'authData': <String, dynamic>{provider: authData}
}));

return _handleResponse(
return await _handleResponse(
this, response, ParseApiRQ.loginWith, _debug, parseClassName);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.loginWith, _debug, parseClassName);
Expand All @@ -246,7 +246,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
final Response response = await _client.post(url,
headers: <String, String>{keyHeaderSessionToken: sessionId});

return _handleResponse(
return await _handleResponse(
this, response, ParseApiRQ.logout, _debug, parseClassName);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.logout, _debug, parseClassName);
Expand All @@ -259,7 +259,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
final Response response = await _client.post(
'${_client.data.serverUrl}$keyEndPointVerificationEmail',
body: json.encode(<String, dynamic>{keyVarEmail: emailAddress}));
return _handleResponse(this, response,
return await _handleResponse(this, response,
ParseApiRQ.verificationEmailRequest, _debug, parseClassName);
} on Exception catch (e) {
return handleException(
Expand All @@ -273,7 +273,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
final Response response = await _client.post(
'${_client.data.serverUrl}$keyEndPointRequestPasswordReset',
body: json.encode(<String, dynamic>{keyVarEmail: emailAddress}));
return _handleResponse(
return await _handleResponse(
this, response, ParseApiRQ.requestPasswordReset, _debug,
parseClassName);
} on Exception catch (e) {
Expand All @@ -289,19 +289,27 @@ class ParseUser extends ParseObject implements ParseCloneable {
@override
Future<ParseResponse> 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<void> _onResponseSuccess() async {
await saveInStorage(keyParseStoreUser);
}

/// Removes a user from Parse Server locally and online
Future<ParseResponse> 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);
Expand Down Expand Up @@ -334,7 +342,7 @@ class ParseUser extends ParseObject implements ParseCloneable {

static Future<dynamic> _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) {
Expand All @@ -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<ParseResponse> _handleResponse(ParseUser user, Response response,
ParseApiRQ type, bool debug, String className) async {
final ParseResponse parseResponse =
handleResponse<ParseUser>(user, response, type, debug, className);

Expand All @@ -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;
}
}
Expand Down