feat: Minor changes
This commit is contained in:
parent
b986096aa0
commit
c086579b57
23
README.md
23
README.md
@ -28,22 +28,25 @@ Include `omemo_dart` in your `pubspec.yaml` like this:
|
||||
dependencies:
|
||||
omemo_dart:
|
||||
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
|
||||
OMEMO messages. As such, `protobuf` is only a dependency for testing that the serialisation and
|
||||
deserialisation of the custom implementation. In order to run tests, you need the Protbuf
|
||||
compiler. After that, making sure that
|
||||
the [Dart Protobuf compiler addon](https://pub.dev/packages/protoc_plugin) and the
|
||||
Protobuf compiler itself is in your PATH,
|
||||
run `protoc -I=./protobuf/ --dart_out=lib/protobuf/ ./protobuf/schema.proto` in the
|
||||
repository's root to generate the real Protobuf bindings.
|
||||
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.
|
||||
In order to allow persistence, your application needs to keep track of the following mappings:
|
||||
|
||||
- `JID -> [int]`: The device list for each JID
|
||||
- `(JID, device) -> Ratchet`: The actual ratchet
|
||||
|
||||
If you also use the `BlindTrustBeforeVerificationTrustManager`, you additionally need to keep track of:
|
||||
|
||||
- `(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
|
||||
tests still pass using `dart test`.
|
||||
|
@ -86,9 +86,13 @@ extension BeforeAfterListDiff<T> on List<T> {
|
||||
|
||||
extension AppendToListOrCreateExtension<K, V> on Map<K, List<V>> {
|
||||
/// 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)) {
|
||||
this[key]!.add(value);
|
||||
if (!checkExistence) {
|
||||
this[key]!.add(value);
|
||||
} if (!this[key]!.contains(value)) {
|
||||
this[key]!.add(value);
|
||||
}
|
||||
} else {
|
||||
this[key] = [value];
|
||||
}
|
||||
|
@ -132,11 +132,8 @@ class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
||||
enablementCache[key] = true;
|
||||
}
|
||||
|
||||
if (devices.containsKey(jid)) {
|
||||
devices[jid]!.add(deviceId);
|
||||
} else {
|
||||
devices[jid] = List<int>.from([deviceId]);
|
||||
}
|
||||
// Append to the device list
|
||||
devices.appendOrCreate(jid, deviceId, checkExistence: true);
|
||||
|
||||
// Commit the state
|
||||
await commit(
|
||||
@ -227,7 +224,7 @@ class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
||||
final key = RatchetMapKey(jid, result.device);
|
||||
trustCache[key] = result.state;
|
||||
enablementCache[key] = result.enabled;
|
||||
devices.appendOrCreate(jid, result.device);
|
||||
devices.appendOrCreate(jid, result.device, checkExistence: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user