Skip to content

Commit

Permalink
- 2.0.2 rc (bug fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrim0 authored and ichorid committed Apr 8, 2023
1 parent c9b3602 commit 41fd264
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 27 deletions.
6 changes: 1 addition & 5 deletions lib/src/core/data/core_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> get props => [token];
Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/ui/widgets/auth/ask_pass_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ Future<void> showAskPassCode({
onUnlocked();
}
: null,
onUnlocked: onUnlocked,
onUnlocked: () {
if (context.mounted) Navigator.of(context).pop();
onUnlocked();
},
onError: (_) {
ScaffoldMessenger.of(context)
.showSnackBar(_wrongPassCodeSnackbar);
Expand Down
11 changes: 7 additions & 4 deletions lib/src/message/data/message_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/vaults/data/secret_shard_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> token) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/vaults/data/vault_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> token) {
Expand Down
11 changes: 5 additions & 6 deletions lib/src/vaults/ui/add_secret/vault_add_secret_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions lib/src/vaults/vault_secret_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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([_]) {
Expand Down

0 comments on commit 41fd264

Please sign in to comment.