From 41fd2649199cbae73f42c967276f364131f35160 Mon Sep 17 00:00:00 2001 From: Postnikov Aleksander Date: Tue, 4 Apr 2023 18:46:02 +0300 Subject: [PATCH] - 2.0.2 rc (bug fix) --- lib/src/core/data/core_model.dart | 6 +----- lib/src/core/ui/widgets/auth/ask_pass_code.dart | 5 ++++- lib/src/message/data/message_model.dart | 11 +++++++---- lib/src/vaults/data/secret_shard_model.dart | 2 +- lib/src/vaults/data/vault_model.dart | 2 +- .../ui/add_secret/vault_add_secret_controller.dart | 11 +++++------ .../vault_recover_secret_controller.dart | 10 ++++------ lib/src/vaults/vault_secret_presenter.dart | 14 +++++++++++--- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/src/core/data/core_model.dart b/lib/src/core/data/core_model.dart index 478c702e..9bbf3aaf 100644 --- a/lib/src/core/data/core_model.dart +++ b/lib/src/core/data/core_model.dart @@ -29,11 +29,7 @@ abstract class IdBase extends Serializable { final String name; final Uint8List token; - IdBase({required this.token, this.name = ' '}) { - if (name.length < minNameLength || name.length > maxNameLength) { - throw const FormatException('Token name length wrong!'); - } - } + const IdBase({required this.token, this.name = ''}); @override List get props => [token]; diff --git a/lib/src/core/ui/widgets/auth/ask_pass_code.dart b/lib/src/core/ui/widgets/auth/ask_pass_code.dart index bfc1fe87..c7e07be3 100644 --- a/lib/src/core/ui/widgets/auth/ask_pass_code.dart +++ b/lib/src/core/ui/widgets/auth/ask_pass_code.dart @@ -37,7 +37,10 @@ Future showAskPassCode({ onUnlocked(); } : null, - onUnlocked: onUnlocked, + onUnlocked: () { + if (context.mounted) Navigator.of(context).pop(); + onUnlocked(); + }, onError: (_) { ScaffoldMessenger.of(context) .showSnackBar(_wrongPassCodeSnackbar); diff --git a/lib/src/message/data/message_model.dart b/lib/src/message/data/message_model.dart index 4773936f..e96d2a78 100644 --- a/lib/src/message/data/message_model.dart +++ b/lib/src/message/data/message_model.dart @@ -122,8 +122,10 @@ class MessageModel extends Serializable { bool get isRequested => status == MessageStatus.created; bool get isNotRequested => status != MessageStatus.created; + bool get isReceived => status == MessageStatus.received; bool get isNotReceived => status != MessageStatus.received; + bool get isAccepted => status == MessageStatus.accepted; bool get isRejected => status == MessageStatus.rejected; bool get isFailed => status == MessageStatus.failed; @@ -132,11 +134,12 @@ class MessageModel extends Serializable { bool get isResolved => status == MessageStatus.accepted || status == MessageStatus.rejected; + bool get isNotResolved => !isResolved; + bool get hasResponse => status != MessageStatus.created && status != MessageStatus.received; - bool get hasNoResponse => - status == MessageStatus.created || status == MessageStatus.received; + bool get hasNoResponse => !hasResponse; factory MessageModel.fromBase64(String value) => MessageModel.fromBytes(base64Decode(value)); @@ -196,9 +199,9 @@ class MessageModel extends Serializable { MessageModel( version: version, id: id, - peerId: peerId ?? this.peerId, - timestamp: timestamp, code: code, + timestamp: timestamp, + peerId: peerId ?? this.peerId, status: status ?? this.status, payload: emptyPayload == true ? null : payload ?? this.payload, ); diff --git a/lib/src/vaults/data/secret_shard_model.dart b/lib/src/vaults/data/secret_shard_model.dart index d6efeb9e..3817283e 100644 --- a/lib/src/vaults/data/secret_shard_model.dart +++ b/lib/src/vaults/data/secret_shard_model.dart @@ -8,7 +8,7 @@ class SecretId extends IdBase { static const currentVersion = 1; static const size = 8; - SecretId({Uint8List? token, required super.name}) + SecretId({Uint8List? token, super.name}) : super(token: token ?? getRandomBytes(size)); factory SecretId.fromBytes(List token) { diff --git a/lib/src/vaults/data/vault_model.dart b/lib/src/vaults/data/vault_model.dart index 35f498d1..c1a97e7d 100644 --- a/lib/src/vaults/data/vault_model.dart +++ b/lib/src/vaults/data/vault_model.dart @@ -8,7 +8,7 @@ class VaultId extends IdBase { static const currentVersion = 1; static const size = 8; - VaultId({Uint8List? token, super.name = ''}) + VaultId({Uint8List? token, super.name}) : super(token: token ?? getRandomBytes(size)); factory VaultId.fromBytes(List token) { diff --git a/lib/src/vaults/ui/add_secret/vault_add_secret_controller.dart b/lib/src/vaults/ui/add_secret/vault_add_secret_controller.dart index 30d3653b..37643015 100644 --- a/lib/src/vaults/ui/add_secret/vault_add_secret_controller.dart +++ b/lib/src/vaults/ui/add_secret/vault_add_secret_controller.dart @@ -26,7 +26,7 @@ class VaultAddSecretController extends VaultSecretPresenter { } VaultAddSecretController({required super.pages, required super.groupId}) - : super(secretId: SecretId(name: '')); + : super(secretId: SecretId()); void startRequest({ required Callback onSuccess, @@ -35,11 +35,10 @@ class VaultAddSecretController extends VaultSecretPresenter { }) { serviceRoot.analyticsService.logEvent(eventStartAddSecret); networkSubscription.onData( - (message) async { - if (message.code != MessageCode.setShard) return; - if (!message.hasResponse) return; - if (!messages.contains(message)) return; - updateMessage(message); + (final incomeMessage) async { + if (incomeMessage.code != MessageCode.setShard) return; + final message = checkAndUpdateMessage(incomeMessage); + if (message == null) return; if (message.isAccepted) { if (messages.where((m) => m.isAccepted).length == group.maxSize) { stopListenResponse(); diff --git a/lib/src/vaults/ui/recover_secret/vault_recover_secret_controller.dart b/lib/src/vaults/ui/recover_secret/vault_recover_secret_controller.dart index 1130403b..b5871afe 100644 --- a/lib/src/vaults/ui/recover_secret/vault_recover_secret_controller.dart +++ b/lib/src/vaults/ui/recover_secret/vault_recover_secret_controller.dart @@ -55,12 +55,10 @@ class VaultRecoverySecretController extends VaultSecretPresenter { void startRequest({required Callback onRejected}) { serviceRoot.analyticsService.logEvent(eventStartRestoreSecret); networkSubscription.onData( - (final message) async { - if (message.code != MessageCode.getShard) return; - if (message.hasNoResponse) return; - final stored = messages.lookup(message); - if (stored == null || stored.hasResponse) return; - updateMessage(message); + (final incomeMessage) async { + if (incomeMessage.code != MessageCode.getShard) return; + final message = checkAndUpdateMessage(incomeMessage); + if (message == null) return; if (messages.where((m) => m.isAccepted).length >= group.threshold) { stopListenResponse(); serviceRoot.analyticsService.logEvent(eventFinishRestoreSecret); diff --git a/lib/src/vaults/vault_secret_presenter.dart b/lib/src/vaults/vault_secret_presenter.dart index a8624441..e9337ab0 100644 --- a/lib/src/vaults/vault_secret_presenter.dart +++ b/lib/src/vaults/vault_secret_presenter.dart @@ -15,10 +15,18 @@ class VaultSecretPresenter extends VaultPresenterBase { group = getVaultById(groupId)!; } - void updateMessage(MessageModel message) { - messages.remove(message); - messages.add(message); + MessageModel? checkAndUpdateMessage(final MessageModel incomeMessage) { + if (incomeMessage.hasNoResponse) return null; + final storedMessage = messages.lookup(incomeMessage); + if (storedMessage == null || storedMessage.hasResponse) return null; + messages.remove(incomeMessage); + final updatedMessage = storedMessage.copyWith( + status: incomeMessage.status, + payload: incomeMessage.payload, + ); + messages.add(updatedMessage); notifyListeners(); + return updatedMessage; } void requestShards([_]) {