Skip to content
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

Fix lint issues #330

Merged
merged 3 commits into from
Dec 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 25 additions & 23 deletions at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ import 'package:at_client/src/util/network_util.dart';
import 'package:at_client/src/util/sync_util.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_commons/src/exception/at_exceptions.dart';
import 'package:at_commons/src/keystore/at_key.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_persistence_secondary_server/src/utils/object_util.dart';
import 'package:at_utils/at_logger.dart';
import 'package:at_utils/at_utils.dart';
import 'package:http/http.dart' as http;
Expand All @@ -58,7 +55,7 @@ class AtClientImpl implements AtClient {

/// Returns a new instance of [AtClient]. App has to pass the current user atSign
/// and the client preference.
@deprecated
@Deprecated("Use AtClientManger to get instance of atClient")
static Future<AtClient?> getClient(String? currentAtSign) async {
if (_atClientInstanceMap.containsKey(currentAtSign)) {
return _atClientInstanceMap[currentAtSign];
Expand All @@ -68,7 +65,7 @@ class AtClientImpl implements AtClient {
return null;
}

@deprecated
@Deprecated("Use [create]")

/// use [create]
static Future<void> createClient(String currentAtSign, String? namespace,
Expand Down Expand Up @@ -158,7 +155,7 @@ class AtClientImpl implements AtClient {
}

@override
@deprecated
@Deprecated("Use SyncManager.sync")
SyncManager? getSyncManager() {
return SyncManagerImpl.getInstance().getSyncManager(currentAtSign);
}
Expand Down Expand Up @@ -209,7 +206,7 @@ class AtClientImpl implements AtClient {
bool isPublic = false,
bool isCached = false,
bool namespaceAware = true}) async {
var keyWithNamespace;
String keyWithNamespace;
if (namespaceAware) {
keyWithNamespace = _getKeyWithNamespace(key);
} else {
Expand All @@ -233,8 +230,8 @@ class AtClientImpl implements AtClient {
bool isCached = false,
bool namespaceAware = true,
String? operation}) async {
var builder;
var keyWithNamespace;
dynamic builder;
String keyWithNamespace;
if (namespaceAware) {
keyWithNamespace = _getKeyWithNamespace(key);
} else {
Expand Down Expand Up @@ -304,7 +301,7 @@ class AtClientImpl implements AtClient {
encryptedResult = _formatResult(encryptedResult)!;
var encryptedResultMap = jsonDecode(encryptedResult);
if (operation == UPDATE_ALL) {
var decryptedValue;
String decryptedValue;
try {
decryptedValue = await _encryptionService!
.decrypt(encryptedResultMap['data'], sharedBy);
Expand Down Expand Up @@ -469,7 +466,7 @@ class AtClientImpl implements AtClient {
isDedicated: isDedicated);
var result = <AtKey>[];
if (getKeysResult.isNotEmpty) {
getKeysResult.forEach((key) {
for (var key in getKeysResult) {
try {
result.add(AtKey.fromString(key));
} on InvalidSyntaxException {
Expand All @@ -478,7 +475,7 @@ class AtClientImpl implements AtClient {
_logger.severe(
'Exception occured: ${e.toString()}. Unable to form key $key');
}
});
}
}
return result;
}
Expand Down Expand Up @@ -571,7 +568,7 @@ class AtClientImpl implements AtClient {
}
}

var putResult;
String? putResult;
try {
if (builder.dataSignature != null) {
builder.isJson = true;
Expand Down Expand Up @@ -739,7 +736,7 @@ class AtClientImpl implements AtClient {
return VALUE;
}
// Verifies if any of the args are not null
var isMetadataNotNull = ObjectsUtil.isAnyNotNull(
var isMetadataNotNull = AtClientUtil.isAnyNotNull(
a1: data!.ttl,
a2: data.ttb,
a3: data.ttr,
Expand Down Expand Up @@ -830,19 +827,20 @@ class AtClientImpl implements AtClient {
.read(maxWaitMilliSeconds: _preference!.outboundConnectionTimeout);
if (streamResult != null && streamResult.startsWith('stream:done')) {
await remoteSecondary.atLookUp.connection!.close();
streamResponse.status = AtStreamStatus.COMPLETE;
streamResponse.status = AtStreamStatus.complete;
}
} else if (result != null && result.startsWith('error:')) {
result = result.replaceAll('error:', '');
streamResponse.errorCode = result.split('-')[0];
streamResponse.errorMessage = result.split('-')[1];
streamResponse.status = AtStreamStatus.ERROR;
streamResponse.status = AtStreamStatus.error;
} else {
streamResponse.status = AtStreamStatus.NO_ACK;
streamResponse.status = AtStreamStatus.noAck;
}
return streamResponse;
}

@override
Future<void> sendStreamAck(
String streamId,
String fileName,
Expand Down Expand Up @@ -870,9 +868,9 @@ class AtClientImpl implements AtClient {
Future<Map<String, FileTransferObject>> uploadFile(
List<File> files, List<String> sharedWithAtSigns) async {
var encryptionKey = _encryptionService!.generateFileEncryptionKey();
var key = TextConstants.FILE_TRANSFER_KEY + Uuid().v4();
var key = TextConstants.fileTransferKey + Uuid().v4();
var fileStatus = await _uploadFiles(key, files, encryptionKey);
var fileUrl = TextConstants.FILEBIN_URL + 'archive/' + key + '/zip';
var fileUrl = TextConstants.fileBinURL + 'archive/' + key + '/zip';
return shareFiles(
sharedWithAtSigns, key, fileUrl, encryptionKey, fileStatus);
}
Expand Down Expand Up @@ -982,10 +980,14 @@ class AtClientImpl implements AtClient {
..key = transferId
..sharedBy = sharedByAtSign;
var result = await get(atKey);
late var fileTransferObject;
FileTransferObject fileTransferObject;
try {
if (FileTransferObject.fromJson(jsonDecode(result.value)) == null) {
_logger.severe("FileTransferObject is null");
throw AtClientException("AT0014", "FileTransferObject is null");
}
fileTransferObject =
FileTransferObject.fromJson(jsonDecode(result.value));
FileTransferObject.fromJson(jsonDecode(result.value))!;
} on Exception catch (e) {
throw Exception('json decode exception in download file ${e.toString()}');
}
Expand Down Expand Up @@ -1015,7 +1017,7 @@ class AtClientImpl implements AtClient {
}
}

@deprecated
@Deprecated("Use EncryptionService")
Future<void> encryptUnEncryptedData() async {
await _encryptionService!.encryptUnencryptedData();
}
Expand All @@ -1035,7 +1037,7 @@ class AtClientImpl implements AtClient {
// Check for internet. Since notify invoke remote secondary directly, network connection
// is mandatory.
if (!await NetworkUtil.isNetworkAvailable()) {
throw AtClientException(at_client_error_codes['AtClientException'],
throw AtClientException(atClientErrorCodes['AtClientException'],
'No network availability');
}
// validate sharedWith atSign
Expand Down
6 changes: 3 additions & 3 deletions at_client/lib/src/client/at_client_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class AtClient {
/// Returns a singleton instance of [SyncManager] that is responsible for syncing data between
/// local secondary server and remote secondary server.
/// [Deprecated] Use [AtClientManager.syncService]
@deprecated
@Deprecated("Use SyncManager.sync")
SyncManager? getSyncManager();

/// Returns a singleton instance of [RemoteSecondary] to communicate with user's secondary server.
Expand Down Expand Up @@ -271,7 +271,7 @@ abstract class AtClient {
/// Notifier: ‘wavi’);
///```
///[Deprecated] Use [AtClientManager.notificationService]
@deprecated
@Deprecated("Use NotificationService")
Future<bool> notify(AtKey key, String value, OperationEnum operation,
{MessageTypeEnum? messageType,
PriorityEnum? priority,
Expand Down Expand Up @@ -398,7 +398,7 @@ abstract class AtClient {
/// the notification on the client.
/// Optionally a regular expression and be passed to filter the notifications
/// [deprecated] Use [NotificationService.subscribe]
@deprecated
@Deprecated("Use Monitor Service")
Future<void> startMonitor(String privateKey, Function acceptStream,
{String? regex});

Expand Down
18 changes: 9 additions & 9 deletions at_client/lib/src/client/local_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LocalSecondary implements Secondary {
/// if [sync] is set to false, no sync operation is done.
@override
Future<String?> executeVerb(VerbBuilder builder, {sync}) async {
var verbResult;
String? verbResult;

try {
if (builder is UpdateVerbBuilder || builder is DeleteVerbBuilder) {
Expand Down Expand Up @@ -69,7 +69,7 @@ class LocalSecondary implements Secondary {

Future<String> _update(UpdateVerbBuilder builder) async {
try {
var updateResult;
dynamic updateResult;
var updateKey = AtClientUtil.buildKey(builder);
switch (builder.operation) {
case UPDATE_META:
Expand Down Expand Up @@ -136,7 +136,7 @@ class LocalSecondary implements Secondary {
}
var llookupMeta = await keyStore!.getMeta(llookupKey);
var isActive = _isActiveKey(llookupMeta);
var result;
String? result;
if (isActive) {
var llookupResult = await keyStore!.get(llookupKey);
result = _prepareResponseData(builder.operation, llookupResult);
Expand Down Expand Up @@ -216,19 +216,19 @@ class LocalSecondary implements Secondary {
if (ttb == null && ttl == null) return true;
var now = DateTime.now().toUtc().millisecondsSinceEpoch;
if (ttb != null) {
var ttb_ms = ttb.toUtc().millisecondsSinceEpoch;
if (ttb_ms > now) return false;
var ttbMs = ttb.toUtc().millisecondsSinceEpoch;
if (ttbMs > now) return false;
}
if (ttl != null) {
var ttl_ms = ttl.toUtc().millisecondsSinceEpoch;
if (ttl_ms < now) return false;
var ttlMs = ttl.toUtc().millisecondsSinceEpoch;
if (ttlMs < now) return false;
}
//If TTB or TTL populated but not met, return true.
return true;
}

String? _prepareResponseData(String? operation, AtData? atData) {
var result;
String? result;
if (atData == null) {
return result;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ class LocalSecondary implements Secondary {

///Returns `true` on successfully storing the values into local secondary.
Future<bool> putValue(String key, String value) async {
var isStored;
dynamic isStored;
var atData = AtData()..data = value;
isStored = await keyStore!.put(key, atData);
return isStored != null ? true : false;
Expand Down
11 changes: 5 additions & 6 deletions at_client/lib/src/client/remote_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:at_client/src/client/secondary.dart';
import 'package:at_client/src/preference/at_client_preference.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_lookup/src/connection/outbound_connection.dart';
import 'package:at_utils/at_logger.dart';
import 'package:at_utils/at_utils.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
Expand All @@ -17,7 +16,7 @@ class RemoteSecondary implements Secondary {

late String _atSign;

late var _preference;
late AtClientPreference _preference;

late AtLookupImpl atLookUp;

Expand All @@ -34,7 +33,7 @@ class RemoteSecondary implements Secondary {
/// Optionally [privateKey] is passed for verb builders which require authentication.
@override
Future<String> executeVerb(VerbBuilder builder, {sync = false}) async {
var verbResult;
String verbResult;
verbResult = await atLookUp.executeVerb(builder);
return verbResult;
}
Expand All @@ -46,7 +45,7 @@ class RemoteSecondary implements Secondary {
}

Future<String?> executeCommand(String atCommand, {bool auth = false}) async {
var verbResult;
String? verbResult;
verbResult = await atLookUp.executeCommand(atCommand, auth: auth);
return verbResult;
}
Expand All @@ -64,7 +63,7 @@ class RemoteSecondary implements Secondary {

/// Generates digest using from verb response and [secret] and performs a CRAM authentication to
/// secondary server
Future<bool> authenticate_cram(var secret) async {
Future<bool> authenticateCram(var secret) async {
var authResult = await atLookUp.authenticate_cram(secret);
return authResult;
}
Expand Down Expand Up @@ -98,7 +97,7 @@ class RemoteSecondary implements Secondary {
var host = secondaryInfo[0];
var port = secondaryInfo[1];
var internetAddress = await InternetAddress.lookup(host);
//#TODO getting first ip for now. explore best solution
//TODO getting first ip for now. explore best solution
var addressCheckOptions =
AddressCheckOptions(internetAddress[0], port: int.parse(port));
return (await InternetConnectionChecker()
Expand Down
2 changes: 1 addition & 1 deletion at_client/lib/src/exception/at_client_error_codes.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Map at_client_error_codes = {
const Map atClientErrorCodes = {
'AtClientException': 'AT0014',
'AtKeyException': 'AT0023',
'PermissionDeniedException': 'AT0024',
Expand Down
2 changes: 1 addition & 1 deletion at_client/lib/src/exception/at_client_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class AtClientException implements Exception {

class AtKeyException extends AtClientException {
AtKeyException(message)
: super(at_client_error_codes['AtKeyException'], message);
: super(atClientErrorCodes['AtKeyException'], message);
}
10 changes: 5 additions & 5 deletions at_client/lib/src/exception/at_client_exception_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:at_commons/at_commons.dart';

class AtClientExceptionUtil {
static String getErrorCode(Exception exception) {
var error_code = error_codes[exception.runtimeType.toString()];
error_code ??= 'AT0014';
return error_code;
var errorCode = error_codes[exception.runtimeType.toString()];
errorCode ??= 'AT0014';
return errorCode;
}

static String? getErrorDescription(String error_code) {
return error_description[error_code];
static String? getErrorDescription(String errorCode) {
return error_description[errorCode];
}
}
7 changes: 3 additions & 4 deletions at_client/lib/src/listener/connectivity_listener.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:internet_connection_checker/internet_connection_checker.dart';

/// Listener class that returns a Stream<True> if internet connection is on in the running device, Stream<False> if internet gets disconnected.
Expand All @@ -13,7 +14,7 @@ import 'package:internet_connection_checker/internet_connection_checker.dart';
/// });
/// ```
class ConnectivityListener {
var _listener;
late StreamSubscription _listener;

/// Listen to [InternetConnectionChecker.onStatusChange] and returns Stream<True> whenever
/// internet connection is online. Returns Stream<False> if internet connection is lost.
Expand All @@ -34,8 +35,6 @@ class ConnectivityListener {

/// Cancels the active subscription to [InternetConnectionChecker]
void unSubscribe() {
if (_listener != null) {
_listener.cancel();
}
_listener.cancel();
}
}
6 changes: 3 additions & 3 deletions at_client/lib/src/manager/at_client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:at_client/src/service/sync_service_impl.dart';
/// atClientManager.syncService - for invoking sync. Refer [SyncService] for detailed usage
/// atClientManager.notificationService - for notification methods. Refer [NotificationService] for detailed usage
class AtClientManager {
var _atSign;
String _atSign = '';
AtClient? _previousAtClient;
late AtClient _currentAtClient;

Expand Down Expand Up @@ -58,8 +58,8 @@ class AtClientManager {
}

void _notifyListeners(SwitchAtSignEvent switchAtSignEvent) {
_changeListeners.forEach((listener) {
for (var listener in _changeListeners) {
listener.listenToAtSignChange(switchAtSignEvent);
});
}
}
}