Add parameter to disable sync post code addition

This commit is contained in:
vishnukvmd 2022-11-11 18:50:26 +05:30
parent be72db844d
commit e84e9db70e
2 changed files with 12 additions and 4 deletions

View file

@ -62,7 +62,7 @@ class AuthenticatorService {
return entries; return entries;
} }
Future<int> addEntry(String plainText) async { Future<int> addEntry(String plainText, bool shouldSync) async {
var key = await getOrCreateAuthDataKey(); var key = await getOrCreateAuthDataKey();
final encryptedKeyData = await CryptoUtil.encryptChaCha( final encryptedKeyData = await CryptoUtil.encryptChaCha(
utf8.encode(plainText) as Uint8List, utf8.encode(plainText) as Uint8List,
@ -71,7 +71,9 @@ class AuthenticatorService {
String encryptedData = Sodium.bin2base64(encryptedKeyData.encryptedData!); String encryptedData = Sodium.bin2base64(encryptedKeyData.encryptedData!);
String header = Sodium.bin2base64(encryptedKeyData.header!); String header = Sodium.bin2base64(encryptedKeyData.header!);
final insertedID = await _db.insert(encryptedData, header); final insertedID = await _db.insert(encryptedData, header);
if (shouldSync) {
unawaited(sync()); unawaited(sync());
}
return insertedID; return insertedID;
} }

View file

@ -31,7 +31,10 @@ class CodeStore {
return codes; return codes;
} }
Future<void> addCode(Code code) async { Future<void> addCode(
Code code, {
bool shouldSync = true,
}) async {
final codes = await getAllCodes(); final codes = await getAllCodes();
for (final existingCode in codes) { for (final existingCode in codes) {
if (existingCode == code) { if (existingCode == code) {
@ -39,7 +42,10 @@ class CodeStore {
return; return;
} }
} }
code.id = await _authenticatorService.addEntry(jsonEncode(code.rawData)); code.id = await _authenticatorService.addEntry(
jsonEncode(code.rawData),
shouldSync,
);
Bus.instance.fire(CodesUpdatedEvent()); Bus.instance.fire(CodesUpdatedEvent());
} }