Skip to content

fix some issues #216

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

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ build/
example/ios/Frameworks/
example/lib/ui/

.vscode/
.vscode/
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class _MyAppState extends State<MyApp> {
Future<void> initData() async {
// Initialize repository
await initRepository();
final CoreStore coreStore = await initCoreStore();
// final CoreStore coreStore = await initCoreStore();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bwcause it is not used yet. so I comment it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a big and will need to be investigated further.


// Initialize parse
await Parse().initialize(keyParseApplicationId, keyParseServerUrl,
Expand Down Expand Up @@ -373,7 +373,6 @@ class _MyAppState extends State<MyApp> {
userRepo ??= UserRepository.init(await getDB());
}


/// Available options:
/// SharedPreferences - Not secure but will work with older versions of SDK - CoreStoreSharedPrefsImpl
/// Sembast - NoSQL DB - Has security - CoreStoreSembastImpl
Expand Down
6 changes: 3 additions & 3 deletions lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class LiveQuery {
securityContext: ParseCoreData().securityContext);

_debug = isDebugEnabled(objectLevelDebug: debug);
_sendSessionId = autoSendSessionId ?? ParseCoreData().autoSendSessionId ?? true;
_sendSessionId =
autoSendSessionId ?? ParseCoreData().autoSendSessionId ?? true;
}

WebSocket _webSocket;
Expand Down Expand Up @@ -40,7 +41,6 @@ class LiveQuery {

// ignore: always_specify_types
Future subscribe(QueryBuilder query) async {

String _liveQueryURL = _client.data.liveQueryURL;
if (_liveQueryURL.contains('https')) {
_liveQueryURL = _liveQueryURL.replaceAll('https', 'wss');
Expand Down Expand Up @@ -101,7 +101,7 @@ class LiveQuery {
if (_debug) {
print('$_printConstLiveQuery: Done');
}
}, onError: (Error error) {
}, onError: (Object error) {
if (_debug) {
print(
'$_printConstLiveQuery: Error: ${error.runtimeType.toString()}');
Expand Down
32 changes: 19 additions & 13 deletions lib/src/objects/parse_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ part of flutter_parse_sdk;
abstract class ParseBase {
String parseClassName;
Type type;
bool _dirty = false; // reserved property
final bool _dirty = false; // reserved property
final Map<String, dynamic> _unsavedChanges = Map<String, dynamic>();
final Map<String, dynamic> _savingChanges = Map<String, dynamic>();

Expand Down Expand Up @@ -41,12 +41,13 @@ abstract class ParseBase {
if (_dirty || _unsavedChanges.isNotEmpty) {
return true;
}
bool match = false;
_getObjectData().forEach((String key, dynamic value) {
if (value is ParseObject && value._areChildrenDirty(seenObjects)) {
return true;
match = true;
}
});
return false;
return match;
}

/// Returns [DateTime] createdAt
Expand Down Expand Up @@ -88,7 +89,8 @@ abstract class ParseBase {
map[keyVarUpdatedAt] = _parseDateFormat.format(updatedAt);
}

final Map<String, dynamic> target = forApiRQ ? _unsavedChanges : _getObjectData();
final Map<String, dynamic> target =
forApiRQ ? _unsavedChanges : _getObjectData();
target.forEach((String key, dynamic value) {
if (!map.containsKey(key)) {
map[key] = parseEncode(value, full: full);
Expand All @@ -100,6 +102,7 @@ abstract class ParseBase {
map.remove(keyVarUpdatedAt);
map.remove(keyVarClassName);
//map.remove(keyVarAcl);
map.remove(keyVarObjectId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this is correct for all calls? Seems strange that it's there in the first place. Have you ran tests that everything else works with this removed? Rather than just installation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do all the test in example. yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works when saving?

I'm not sure saving an object would work anymore. It will create a new object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phillwiggins
I'm seeing that they removed the ACL from ParseObject, the code was commented out. When was it done? I've added this functionality to lib and am using this in version 21 on a large project and have not had problem.

map.remove(keyParamSessionToken);
}

Expand Down Expand Up @@ -152,7 +155,8 @@ abstract class ParseBase {

/// Returns the objects variables
@protected
Map<String, dynamic> _getObjectData() => _objectData ?? Map<String, dynamic>();
Map<String, dynamic> _getObjectData() =>
_objectData ?? Map<String, dynamic>();

bool containsValue(Object value) {
return _getObjectData().containsValue(value);
Expand All @@ -169,11 +173,11 @@ abstract class ParseBase {
void operator []=(String key, dynamic value) {
set<dynamic>(key, value);
}

/// Saves in storage
Future<void> saveInStorage(String key) async {
final String objectJson = json.encode(toJson(full: true));
ParseCoreData().getStore()
..setString(key, objectJson);
ParseCoreData().getStore()..setString(key, objectJson);
}

/// Sets type [T] from objectData
Expand Down Expand Up @@ -237,8 +241,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);
ParseCoreData().getStore()..setString(objectId, json);
return true;
} else {
return false;
Expand All @@ -250,8 +253,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);
ParseCoreData().getStore()..remove(key ?? objectId);
return true;
}

Expand Down Expand Up @@ -282,10 +284,14 @@ abstract class ParseBase {
String getClassName() => parseClassName;
@Deprecated('Prefer to use parseClassName')
String setClassName(String className) => parseClassName = className;
@protected @Deprecated('Prefer to use _getObjectData method, or operator [] for certain key.')
@protected
@Deprecated(
'Prefer to use _getObjectData method, or operator [] for certain key.')
Map<String, dynamic> getObjectData() => _getObjectData();

@protected @Deprecated('Prefer to use _setObjectData method, or operator [] for certain key.')
@protected
@Deprecated(
'Prefer to use _setObjectData method, or operator [] for certain key.')
void setObjectData(Map<String, dynamic> objectData) =>
_setObjectData(objectData);
}
4 changes: 2 additions & 2 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 @@ -183,7 +183,7 @@ class ParseInstallation extends ParseObject {

/// Saves the current object online
Future<ParseResponse> _save() async {
if (objectId== null) {
if (objectId == null) {
return create();
} else {
try {
Expand Down
14 changes: 6 additions & 8 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
if (response != null) {
if (response.success) {
_savingChanges.clear();
}
else {
} else {
_revertSavingChanges();
}
}
Expand Down Expand Up @@ -162,9 +161,9 @@ class ParseObject extends ParseBase implements ParseCloneable {
final List<dynamic> requests = chunk.map<dynamic>((ParseObject obj) {
return obj._getRequestJson(obj.objectId == null ? 'POST' : 'PUT');
}).toList();
chunk.forEach((ParseObject obj) {
for (ParseObject obj in chunk) {
obj._saveChanges();
});
}
final ParseResponse response = await batchRequest(requests, chunk);
totalResponse.success &= response.success;
if (response.success) {
Expand All @@ -174,16 +173,15 @@ class ParseObject extends ParseBase implements ParseCloneable {
if (response.results[i] is ParseError) {
// Batch request succeed, but part of batch failed.
chunk[i]._revertSavingChanges();
}
else {
} else {
chunk[i]._savingChanges.clear();
}
}
} else {
// If there was an error, we want to roll forward the save changes before rethrowing.
chunk.forEach((ParseObject obj) {
for (ParseObject obj in chunk) {
obj._revertSavingChanges();
});
}
totalResponse.statusCode = response.statusCode;
totalResponse.error = response.error;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
return _handleResponse(
this, response, ParseApiRQ.loginAnonymous, _debug, parseClassName);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.loginAnonymous, _debug, parseClassName);
return handleException(
e, ParseApiRQ.loginAnonymous, _debug, parseClassName);
}
}

Expand Down Expand Up @@ -269,8 +270,8 @@ 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(
this, response, ParseApiRQ.requestPasswordReset, _debug, parseClassName);
return _handleResponse(this, response, ParseApiRQ.requestPasswordReset,
_debug, parseClassName);
} on Exception catch (e) {
return handleException(
e, ParseApiRQ.requestPasswordReset, _debug, parseClassName);
Expand Down Expand Up @@ -329,7 +330,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 Down