Skip to content

Commit

Permalink
History saved on tag rename
Browse files Browse the repository at this point in the history
  • Loading branch information
GleammerRay committed Mar 23, 2024
1 parent 6450724 commit a7f8fc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 22 additions & 1 deletion lib/passy_data/loaded_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1109,13 +1109,34 @@ class LoadedAccount {
required String tag,
required String newTag,
}) async {
await Future.wait([
List<List<String>> keyLists = await Future.wait([
_passwords.renameTag(tag: tag, newTag: newTag),
_notes.renameTag(tag: tag, newTag: newTag),
_paymentCards.renameTag(tag: tag, newTag: newTag),
_identities.renameTag(tag: tag, newTag: newTag),
_idCards.renameTag(tag: tag, newTag: newTag),
]);
for (String passwordKey in keyLists[0]) {
_history.value.passwords[passwordKey] = EntryEvent(passwordKey,
status: EntryStatus.alive, lastModified: DateTime.now().toUtc());
}
for (String notesKey in keyLists[1]) {
_history.value.notes[notesKey] = EntryEvent(notesKey,
status: EntryStatus.alive, lastModified: DateTime.now().toUtc());
}
for (String paymentCardKey in keyLists[2]) {
_history.value.paymentCards[paymentCardKey] = EntryEvent(paymentCardKey,
status: EntryStatus.alive, lastModified: DateTime.now().toUtc());
}
for (String identityKey in keyLists[3]) {
_history.value.identities[identityKey] = EntryEvent(identityKey,
status: EntryStatus.alive, lastModified: DateTime.now().toUtc());
}
for (String idCardKey in keyLists[4]) {
_history.value.idCards[idCardKey] = EntryEvent(idCardKey,
status: EntryStatus.alive, lastModified: DateTime.now().toUtc());
}
await _history.save();
}

// Passwords wrappers
Expand Down
7 changes: 6 additions & 1 deletion lib/passy_data/passy_entries_encrypted_csv_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,11 @@ class PassyEntriesEncryptedCSVFile<T extends PassyEntry<T>> {
await _raf.close();
}

Future<void> renameTag({
Future<List<String>> renameTag({
required String tag,
required String newTag,
}) async {
List<String> keys = [];
RandomAccessFile _raf = await _file.open();
if (skipLine(_raf, lineDelimiter: ',') == -1) {
await _raf.close();
Expand All @@ -408,12 +409,15 @@ class PassyEntriesEncryptedCSVFile<T extends PassyEntry<T>> {
return true;
}
var tagList = _csv[_tagIndex];
bool _changed = false;
for (dynamic oldTag in (tagList as List<dynamic>).toList()) {
oldTag = oldTag.toString();
if (oldTag != tag) continue;
_changed = true;
tagList.remove(tag);
tagList.add(newTag);
}
if (_changed) keys.add(_decoded[0]);
entry = _encodeEntryForSaving(_csv);
await _tempRaf.writeString(entry);
if (skipLine(_raf, lineDelimiter: ',') == -1) return true;
Expand All @@ -424,5 +428,6 @@ class PassyEntriesEncryptedCSVFile<T extends PassyEntry<T>> {
await _file.delete();
await _tempFile.copy(_file.absolute.path);
await _tempFile.delete();
return keys;
}
}

0 comments on commit a7f8fc5

Please sign in to comment.