feat: Minor changes

This commit is contained in:
PapaTutuWawa 2023-06-17 23:23:41 +02:00
parent b986096aa0
commit c086579b57
3 changed files with 22 additions and 18 deletions

View File

@ -28,22 +28,25 @@ Include `omemo_dart` in your `pubspec.yaml` like this:
dependencies: dependencies:
omemo_dart: omemo_dart:
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
version: ^0.4.3 version: ^0.5.0
# [...] # [...]
# [...] # [...]
``` ```
## Contributing ### Persistence
Due to issues with `protobuf`, `omemo_dart` reimplements the Protobuf encoding for the required By default, `omemo_dart` uses in-memory implementations for everything. For a real-world application, this is unsuitable as OMEMO devices would be constantly added.
OMEMO messages. As such, `protobuf` is only a dependency for testing that the serialisation and In order to allow persistence, your application needs to keep track of the following mappings:
deserialisation of the custom implementation. In order to run tests, you need the Protbuf
compiler. After that, making sure that - `JID -> [int]`: The device list for each JID
the [Dart Protobuf compiler addon](https://pub.dev/packages/protoc_plugin) and the - `(JID, device) -> Ratchet`: The actual ratchet
Protobuf compiler itself is in your PATH,
run `protoc -I=./protobuf/ --dart_out=lib/protobuf/ ./protobuf/schema.proto` in the If you also use the `BlindTrustBeforeVerificationTrustManager`, you additionally need to keep track of:
repository's root to generate the real Protobuf bindings.
- `(JID, device) -> (int, bool)`: The trust level and the enablement state
## Contributing
When submitting a PR, please run the linter using `dart analyze` and make sure that all When submitting a PR, please run the linter using `dart analyze` and make sure that all
tests still pass using `dart test`. tests still pass using `dart test`.

View File

@ -86,9 +86,13 @@ extension BeforeAfterListDiff<T> on List<T> {
extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> { extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> {
/// Create or append [value] to the list identified with key [key]. /// Create or append [value] to the list identified with key [key].
void appendOrCreate(K key, V value) { void appendOrCreate(K key, V value, {bool checkExistence = false}) {
if (containsKey(key)) { if (containsKey(key)) {
if (!checkExistence) {
this[key]!.add(value); this[key]!.add(value);
} if (!this[key]!.contains(value)) {
this[key]!.add(value);
}
} else { } else {
this[key] = [value]; this[key] = [value];
} }

View File

@ -132,11 +132,8 @@ class BlindTrustBeforeVerificationTrustManager extends TrustManager {
enablementCache[key] = true; enablementCache[key] = true;
} }
if (devices.containsKey(jid)) { // Append to the device list
devices[jid]!.add(deviceId); devices.appendOrCreate(jid, deviceId, checkExistence: true);
} else {
devices[jid] = List<int>.from([deviceId]);
}
// Commit the state // Commit the state
await commit( await commit(
@ -227,7 +224,7 @@ class BlindTrustBeforeVerificationTrustManager extends TrustManager {
final key = RatchetMapKey(jid, result.device); final key = RatchetMapKey(jid, result.device);
trustCache[key] = result.state; trustCache[key] = result.state;
enablementCache[key] = result.enabled; enablementCache[key] = result.enabled;
devices.appendOrCreate(jid, result.device); devices.appendOrCreate(jid, result.device, checkExistence: true);
} }
} }