refactor: Move pedantic to dev_dependencies

The unawaited method from the pedantic package was a historic solution
for the case that you dont want to await a future in an async function.
But now we can do this with just a comment which
is the recommended way to do this now.
This makes it possible to have pedantic as a dev_dependency which means just one dependency less.
This commit is contained in:
Christian Pauly 2021-06-18 10:15:59 +02:00
parent 45a2472fcd
commit 69b52ba85b
5 changed files with 33 additions and 24 deletions

View File

@ -19,7 +19,6 @@
import 'dart:convert';
import 'dart:async';
import 'package:pedantic/pedantic.dart';
import 'package:olm/olm.dart' as olm;
import '../matrix.dart';
@ -106,26 +105,31 @@ class Encryption {
.contains(event.type)) {
// "just" room key request things. We don't need these asap, so we handle
// them in the background
unawaited(runInRoot(() => keyManager.handleToDeviceEvent(event)));
// ignore: unawaited_futures
runInRoot(() => keyManager.handleToDeviceEvent(event));
}
if (event.type == EventTypes.Dummy) {
// the previous device just had to create a new olm session, due to olm session
// corruption. We want to try to send it the last message we just sent it, if possible
unawaited(runInRoot(() => olmManager.handleToDeviceEvent(event)));
// ignore: unawaited_futures
runInRoot(() => olmManager.handleToDeviceEvent(event));
}
if (event.type.startsWith('m.key.verification.')) {
// some key verification event. No need to handle it now, we can easily
// do this in the background
unawaited(
runInRoot(() => keyVerificationManager.handleToDeviceEvent(event)));
// ignore: unawaited_futures
runInRoot(() => keyVerificationManager.handleToDeviceEvent(event));
}
if (event.type.startsWith('m.secret.')) {
// some ssss thing. We can do this in the background
unawaited(runInRoot(() => ssss.handleToDeviceEvent(event)));
// ignore: unawaited_futures
runInRoot(() => ssss.handleToDeviceEvent(event));
}
if (event.sender == client.userID) {
// maybe we need to re-try SSSS secrets
unawaited(runInRoot(() => ssss.periodicallyRequestMissingCache()));
// ignore: unawaited_futures
runInRoot(() => ssss.periodicallyRequestMissingCache());
}
}
@ -139,14 +143,16 @@ class Encryption {
update.content['content']['msgtype']
.startsWith('m.key.verification.'))) {
// "just" key verification, no need to do this in sync
unawaited(
runInRoot(() => keyVerificationManager.handleEventUpdate(update)));
// ignore: unawaited_futures
runInRoot(() => keyVerificationManager.handleEventUpdate(update));
}
if (update.content['sender'] == client.userID &&
(!update.content.containsKey('unsigned') ||
!update.content['unsigned'].containsKey('transaction_id'))) {
// maybe we need to re-try SSSS secrets
unawaited(runInRoot(() => ssss.periodicallyRequestMissingCache()));
// ignore: unawaited_futures
runInRoot(() => ssss.periodicallyRequestMissingCache());
}
}

View File

@ -21,7 +21,6 @@ import 'dart:convert';
import 'package:canonical_json/canonical_json.dart';
import 'package:matrix/matrix.dart';
import 'package:olm/olm.dart' as olm;
import 'package:pedantic/pedantic.dart';
import '../encryption/utils/json_signature_check_extension.dart';
import 'encryption.dart';
@ -502,8 +501,8 @@ class OlmManager {
} catch (_) {
// okay, the thing errored while decrypting. It is safe to assume that the olm session is corrupt and we should generate a new one
if (client.enableE2eeRecovery) {
unawaited(
runInRoot(() => restoreOlmSession(event.senderId, senderKey)));
// ignore: unawaited_futures
runInRoot(() => restoreOlmSession(event.senderId, senderKey));
}
rethrow;
}

View File

@ -21,7 +21,6 @@ import 'dart:typed_data';
import 'package:canonical_json/canonical_json.dart';
import 'package:olm/olm.dart' as olm;
import 'package:pedantic/pedantic.dart';
import '../../matrix.dart';
import '../encryption.dart';
@ -457,8 +456,9 @@ class KeyVerification {
// no need to request cache, we already have it
return;
}
unawaited(encryption.ssss
.maybeRequestAll(_verifiedDevices.whereType<DeviceKeys>().toList()));
// ignore: unawaited_futures
encryption.ssss
.maybeRequestAll(_verifiedDevices.whereType<DeviceKeys>().toList());
if (requestInterval.length <= i) {
return;
}
@ -500,7 +500,8 @@ class KeyVerification {
if (verifiedMasterKey && userId == client.userID) {
// it was our own master key, let's request the cross signing keys
// we do it in the background, thus no await needed here
unawaited(maybeRequestSSSSSecrets());
// ignore: unawaited_futures
maybeRequestSSSSSecrets();
}
await send(EventTypes.KeyVerificationDone, {});
@ -510,7 +511,8 @@ class KeyVerification {
// these keys can be signed! Let's do so
if (await encryption.crossSigning.isCached()) {
// and now let's sign them all in the background
unawaited(encryption.crossSigning.sign(_verifiedDevices));
// ignore: unawaited_futures
encryption.crossSigning.sign(_verifiedDevices);
} else if (!wasUnknownSession) {
askingSSSS = true;
}

View File

@ -24,7 +24,6 @@ import 'dart:typed_data';
import 'package:matrix/src/utils/run_in_root.dart';
import 'package:http/http.dart' as http;
import 'package:olm/olm.dart' as olm;
import 'package:pedantic/pedantic.dart';
import '../encryption.dart';
import '../matrix.dart';
@ -677,7 +676,8 @@ class Client extends MatrixApi {
await super.setTyping(userId, roomId, typing, timeout: timeout);
final room = getRoomById(roomId);
if (typing && room != null && encryptionEnabled && room.encrypted) {
unawaited(encryption.keyManager.prepareOutboundGroupSession(roomId));
// ignore: unawaited_futures
encryption.keyManager.prepareOutboundGroupSession(roomId);
}
}
@ -1890,7 +1890,8 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
}
// now send out the background chunks
if (i < deviceKeys.length) {
unawaited(() async {
// ignore: unawaited_futures
() async {
for (; i < deviceKeys.length; i += chunkSize) {
// wait 50ms to not freeze the UI
await Future.delayed(Duration(milliseconds: 50));
@ -1901,9 +1902,10 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
? deviceKeys.length
: i + chunkSize);
// and send
unawaited(sendToDeviceEncrypted(chunk, eventType, message));
// ignore: unawaited_futures
sendToDeviceEncrypted(chunk, eventType, message);
}
}());
}();
}
}

View File

@ -20,11 +20,11 @@ dependencies:
isolate: ^2.0.3
matrix_api_lite: ^0.3.3
hive: ^2.0.4
pedantic: ^1.11.0
ffi: ^1.0.0
js: ^0.6.3
dev_dependencies:
pedantic: ^1.11.0
test: ^1.15.7
coverage: ">=0.15.0 <2.0.0"
moor_generator: ^4.0.0