Skip to content

refactor: Fix deprecations and other warnings #810

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 3 commits into from
Dec 21, 2022
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
40 changes: 20 additions & 20 deletions packages/dart/lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Subscription<T extends ParseObject> {
}
}

enum LiveQueryClientEvent { CONNECTED, DISCONNECTED, USER_DISCONNECTED }
enum LiveQueryClientEvent { connected, disconnected, userDisconnected }

class LiveQueryReconnectingController {
LiveQueryReconnectingController(
Expand All @@ -50,16 +50,16 @@ class LiveQueryReconnectingController {
}
_eventStream.listen((LiveQueryClientEvent event) {
switch (event) {
case LiveQueryClientEvent.CONNECTED:
case LiveQueryClientEvent.connected:
_isConnected = true;
_retryState = 0;
_userDisconnected = false;
break;
case LiveQueryClientEvent.DISCONNECTED:
case LiveQueryClientEvent.disconnected:
_isConnected = false;
_setReconnect();
break;
case LiveQueryClientEvent.USER_DISCONNECTED:
case LiveQueryClientEvent.userDisconnected:
_userDisconnected = true;
Timer? currentTimer = _currentTimer;
if (currentTimer != null) {
Expand All @@ -70,14 +70,14 @@ class LiveQueryReconnectingController {
}

if (debug) {
print('$DEBUG_TAG: $event');
print('$debugTag: $event');
}
});
ParseCoreData().appResumedStream?.listen((void _) => _setReconnect());
}

static List<int> get retryInterval => ParseCoreData().liveListRetryIntervals;
static const String DEBUG_TAG = 'LiveQueryReconnectingController';
static const String debugTag = 'LiveQueryReconnectingController';

final Function _reconnect;
final Stream<LiveQueryClientEvent> _eventStream;
Expand All @@ -99,7 +99,7 @@ class LiveQueryReconnectingController {
_isConnected = false;
}
if (debug) {
print('$DEBUG_TAG: $state');
print('$debugTag: $state');
}
_setReconnect();
}
Expand All @@ -116,7 +116,7 @@ class LiveQueryReconnectingController {
_reconnect();
});
if (debug) {
print('$DEBUG_TAG: Retrytimer set to ${retryInterval[_retryState]}ms');
print('$debugTag: Retry timer set to ${retryInterval[_retryState]}ms');
}
if (_retryState < retryInterval.length - 1) {
_retryState++;
Expand Down Expand Up @@ -188,13 +188,13 @@ class LiveQueryClient {
if (webSocket != null) {
return webSocket.readyState;
}
return parse_web_socket.WebSocket.CONNECTING;
return parse_web_socket.WebSocket.connecting;
}

Future<dynamic> disconnect({bool userInitialized = false}) async {
parse_web_socket.WebSocket? webSocket = _webSocket;
if (webSocket != null &&
webSocket.readyState == parse_web_socket.WebSocket.OPEN) {
webSocket.readyState == parse_web_socket.WebSocket.open) {
if (_debug) {
print('$_printConstLiveQuery: Socket closed');
}
Expand All @@ -215,7 +215,7 @@ class LiveQueryClient {
_connecting = false;
if (userInitialized) {
_clientEventStreamController.sink
.add(LiveQueryClientEvent.USER_DISCONNECTED);
.add(LiveQueryClientEvent.userDisconnected);
}
}

Expand All @@ -224,7 +224,7 @@ class LiveQueryClient {
{T? copyObject}) async {
if (_webSocket == null) {
await _clientEventStream.any((LiveQueryClientEvent event) =>
event == LiveQueryClientEvent.CONNECTED);
event == LiveQueryClientEvent.connected);
}
final int requestId = _requestIdGenerator();
final Subscription<T> subscription =
Expand Down Expand Up @@ -272,7 +272,7 @@ class LiveQueryClient {
await parse_web_socket.WebSocket.connect(_liveQueryURL);
_webSocket = webSocket;
_connecting = false;
if (webSocket.readyState == parse_web_socket.WebSocket.OPEN) {
if (webSocket.readyState == parse_web_socket.WebSocket.open) {
if (_debug) {
print('$_printConstLiveQuery: Socket opened');
}
Expand All @@ -288,13 +288,13 @@ class LiveQueryClient {
_handleMessage(message);
}, onDone: () {
_clientEventStreamController.sink
.add(LiveQueryClientEvent.DISCONNECTED);
.add(LiveQueryClientEvent.disconnected);
if (_debug) {
print('$_printConstLiveQuery: Done');
}
}, onError: (Object error) {
_clientEventStreamController.sink
.add(LiveQueryClientEvent.DISCONNECTED);
.add(LiveQueryClientEvent.disconnected);
if (_debug) {
print(
'$_printConstLiveQuery: Error: ${error.runtimeType.toString()}');
Expand All @@ -307,7 +307,7 @@ class LiveQueryClient {
});
} on Exception catch (e) {
_connecting = false;
_clientEventStreamController.sink.add(LiveQueryClientEvent.DISCONNECTED);
_clientEventStreamController.sink.add(LiveQueryClientEvent.disconnected);
if (_debug) {
print('$_printConstLiveQuery: Error: ${e.toString()}');
}
Expand Down Expand Up @@ -390,12 +390,12 @@ class LiveQueryClient {

Subscription? subscription;
if (actionData.containsKey('op') && actionData['op'] == 'connected') {
print('ReSubScription:$_requestSubscription');
print('Re subscription:$_requestSubscription');

_requestSubscription.values.toList().forEach((Subscription subcription) {
_subscribeLiveQuery(subcription);
_requestSubscription.values.toList().forEach((Subscription subscription) {
_subscribeLiveQuery(subscription);
});
_clientEventStreamController.sink.add(LiveQueryClientEvent.CONNECTED);
_clientEventStreamController.sink.add(LiveQueryClientEvent.connected);
return;
}
if (actionData.containsKey('requestId')) {
Expand Down
60 changes: 30 additions & 30 deletions packages/dart/lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class QueryBuilder<T extends ParseObject> {
query += '{' + list[i].buildQueries(list[i].queries) + '}';
}
query += ']';
queries.add(MapEntry<String, dynamic>(_NO_OPERATOR_NEEDED, query));
queries.add(MapEntry<String, dynamic>(_noOperatorNeeded, query));
}

factory QueryBuilder.copy(QueryBuilder<T> query) {
Expand All @@ -32,8 +32,8 @@ class QueryBuilder<T extends ParseObject> {
return copy;
}

static const String _NO_OPERATOR_NEEDED = 'NO_OP';
static const String _SINGLE_QUERY = 'SINGLE_QUERY';
static const String _noOperatorNeeded = 'NO_OP';
static const String _singleQuery = 'SINGLE_QUERY';

T object;
List<MapEntry<String, dynamic>> queries = <MapEntry<String, dynamic>>[];
Expand Down Expand Up @@ -103,10 +103,10 @@ class QueryBuilder<T extends ParseObject> {
{bool caseSensitive = false}) {
if (caseSensitive) {
queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$regex": "^$query"}'));
_singleQuery, '"$column":{"\$regex": "^$query"}'));
} else {
queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$regex": "^$query", "\$options": "i"}'));
_singleQuery, '"$column":{"\$regex": "^$query", "\$options": "i"}'));
}
}

Expand All @@ -115,17 +115,17 @@ class QueryBuilder<T extends ParseObject> {
{bool caseSensitive = false}) {
if (caseSensitive) {
queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$regex": "$query\$"}'));
_singleQuery, '"$column":{"\$regex": "$query\$"}'));
} else {
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
'"$column":{"\$regex": "$query\$", "\$options": "i"}'));
queries.add(MapEntry<String, dynamic>(
_singleQuery, '"$column":{"\$regex": "$query\$", "\$options": "i"}'));
}
}

/// Returns an object where the [String] column equals [value]
void whereEqualTo(String column, dynamic value) {
queries.add(_buildQueryWithColumnValueAndOperator(
MapEntry<String, dynamic>(column, value), _NO_OPERATOR_NEEDED));
MapEntry<String, dynamic>(column, value), _noOperatorNeeded));
}

/// Returns an object where the [String] column contains a value less than
Expand Down Expand Up @@ -182,7 +182,7 @@ class QueryBuilder<T extends ParseObject> {

/// Retrieves related objets where [String] column is a relation field to the class [String] className
void whereRelatedTo(String column, String className, String objectId) {
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"\$relatedTo":{"object":{"__type":"Pointer","className":"$className","objectId":"$objectId"},"key":"$column"}'));
}

Expand Down Expand Up @@ -216,20 +216,20 @@ class QueryBuilder<T extends ParseObject> {
{bool caseSensitive = false}) {
if (caseSensitive) {
queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$regex": "$value"}'));
_singleQuery, '"$column":{"\$regex": "$value"}'));
} else {
queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$regex": "$value", "\$options": "i"}'));
_singleQuery, '"$column":{"\$regex": "$value", "\$options": "i"}'));
}
}

/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including wether they are case sensitive or not.
/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including whether they are case sensitive or not.
/// This search can also order by the score of the search
void whereContainsWholeWord(String column, String query,
{bool caseSensitive = false,
bool orderByScore = true,
bool diacriticSensitive = false}) {
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$text":{"\$search":{"\$term": "$query", "\$caseSensitive": $caseSensitive , "\$diacriticSensitive": $diacriticSensitive }}}'));
if (orderByScore) {
orderByAscending('\$score');
Expand All @@ -241,7 +241,7 @@ class QueryBuilder<T extends ParseObject> {
void whereNear(String column, ParseGeoPoint point) {
final double latitude = point.latitude;
final double longitude = point.longitude;
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude}}'));
}

Expand All @@ -251,7 +251,7 @@ class QueryBuilder<T extends ParseObject> {
final double latitude = point.latitude;
final double longitude = point.longitude;

queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInMiles":$maxDistance}'));
}

Expand All @@ -261,7 +261,7 @@ class QueryBuilder<T extends ParseObject> {
final double latitude = point.latitude;
final double longitude = point.longitude;

queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInKilometers":$maxDistance}'));
}

Expand All @@ -271,7 +271,7 @@ class QueryBuilder<T extends ParseObject> {
final double latitude = point.latitude;
final double longitude = point.longitude;

queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$nearSphere":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude},"\$maxDistanceInRadians":$maxDistance}'));
}

Expand All @@ -284,7 +284,7 @@ class QueryBuilder<T extends ParseObject> {
final double latitudeN = northeast.latitude;
final double longitudeN = northeast.longitude;

queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$within":{"\$box": [{"__type": "GeoPoint","latitude":$latitudeS,"longitude":$longitudeS},{"__type": "GeoPoint","latitude":$latitudeN,"longitude":$longitudeN}]}}'));
}

Expand All @@ -299,7 +299,7 @@ class QueryBuilder<T extends ParseObject> {
dictionary['\$polygon'] = points.map((e) => e.toJson()).toList();

queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
_singleQuery, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
}

/// Add a constraint to the query that requires a particular key's value match another QueryBuilder
Expand All @@ -309,7 +309,7 @@ class QueryBuilder<T extends ParseObject> {
query._buildQueryRelational(query.object.parseClassName);

queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$inQuery":$inQuery}'));
_singleQuery, '"$column":{"\$inQuery":$inQuery}'));
}

///Add a constraint to the query that requires a particular key's value does not match another QueryBuilder
Expand All @@ -319,7 +319,7 @@ class QueryBuilder<T extends ParseObject> {
query._buildQueryRelational(query.object.parseClassName);

queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$notInQuery":$inQuery}'));
_singleQuery, '"$column":{"\$notInQuery":$inQuery}'));
}

/// Add a constraint to the query that requires a particular key's value matches a value for a key in the results of another ParseQuery.
Expand All @@ -339,7 +339,7 @@ class QueryBuilder<T extends ParseObject> {
query._buildQueryRelationalKey(query.object.parseClassName, keyInQuery);

queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$select":$inQuery}'));
_singleQuery, '"$column":{"\$select":$inQuery}'));
}

/// Add a constraint to the query that requires a particular key's value does not match any value for a key in the results of another ParseQuery
Expand All @@ -359,7 +359,7 @@ class QueryBuilder<T extends ParseObject> {
query._buildQueryRelationalKey(query.object.parseClassName, keyInQuery);

queries.add(MapEntry<String, dynamic>(
_SINGLE_QUERY, '"$column":{"\$dontSelect":$inQuery}'));
_singleQuery, '"$column":{"\$dontSelect":$inQuery}'));
}

/// Finishes the query and calls the server
Expand Down Expand Up @@ -445,9 +445,9 @@ class QueryBuilder<T extends ParseObject> {
final dynamic value =
convertValueToCorrectType(parseEncode(columnAndValue.value));

if (queryOperator == _NO_OPERATOR_NEEDED) {
if (queryOperator == _noOperatorNeeded) {
return MapEntry<String, dynamic>(
_NO_OPERATOR_NEEDED, '"$key": ${jsonEncode(value)}');
_noOperatorNeeded, '"$key": ${jsonEncode(value)}');
} else {
String queryString = '"$key":';
final Map<String, dynamic> queryOperatorAndValueMap = <String, dynamic>{};
Expand All @@ -470,15 +470,15 @@ class QueryBuilder<T extends ParseObject> {
// Run through each query
for (final MapEntry<String, dynamic> query in queries) {
// Add queries that don't need sanitizing
if (query.key == _NO_OPERATOR_NEEDED || query.key == _SINGLE_QUERY) {
if (query.key == _noOperatorNeeded || query.key == _singleQuery) {
sanitizedQueries
.add(MapEntry<String, dynamic>(_NO_OPERATOR_NEEDED, query.value));
.add(MapEntry<String, dynamic>(_noOperatorNeeded, query.value));
}

// Check if query with same column name has been sanitized
if (!keysAlreadyCompacted.contains(query.key) &&
query.key != _NO_OPERATOR_NEEDED &&
query.key != _SINGLE_QUERY) {
query.key != _noOperatorNeeded &&
query.key != _singleQuery) {
// If not, check that it now has
keysAlreadyCompacted.add(query.key);

Expand Down
8 changes: 4 additions & 4 deletions packages/dart/lib/src/network/parse_websocket_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import 'package:web_socket_channel/web_socket_channel.dart';
class WebSocket {
WebSocket._(this._webSocket);

static const int CONNECTING = 0;
static const int OPEN = 1;
static const int CLOSING = 2;
static const int CLOSED = 3;
static const int connecting = 0;
static const int open = 1;
static const int closing = 2;
static const int closed = 3;

final html.WebSocket _webSocket;

Expand Down
8 changes: 4 additions & 4 deletions packages/dart/lib/src/network/parse_websocket_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import 'package:web_socket_channel/web_socket_channel.dart';
class WebSocket {
WebSocket._(this._webSocket);

static const int CONNECTING = 0;
static const int OPEN = 1;
static const int CLOSING = 2;
static const int CLOSED = 3;
static const int connecting = 0;
static const int open = 1;
static const int closing = 2;
static const int closed = 3;

final io.WebSocket _webSocket;

Expand Down
Loading