upsertAll method
Encrypt multiple messages and put them into the database
Implementation
Future<void> upsertAll(List<LocalityEvent> messages, String flag, {String? password}) async {
final key = password ?? _defaultPassword;
final batch = _database.batch();
for (var message in messages) {
final encryptedPayload = PayloadCipher.encodePayload(
message.payload,
nonce: Nonce.fromString(message.uuid),
chaCha20: ChaCha20(ChaCha20Key.fromString(key))
);
final messageMap = message.toMap();
messageMap[LocalityEvent.columnPayload] = encryptedPayload;
batch.insert(
LocalityEvent.tableName,
messageMap,
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
await batch.commit(noResult: true);
}