diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index b1e80ed9..f0f2d16d 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/matrix_api_lite.dart b/lib/matrix_api_lite.dart index 3a638c49..d6251d92 100644 --- a/lib/matrix_api_lite.dart +++ b/lib/matrix_api_lite.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -24,17 +23,32 @@ library matrix_api_lite; -export 'src/matrix_api.dart'; -export 'src/values.dart'; export 'src/generated/model.dart'; -export 'src/utils/logs.dart'; -export 'src/utils/map_copy_extension.dart'; -export 'src/utils/try_get_map_extension.dart'; +export 'src/matrix_api.dart'; export 'src/model/algorithm_types.dart'; +export 'src/model/auth/authentication_data.dart'; +export 'src/model/auth/authentication_identifier.dart'; +export 'src/model/auth/authentication_password.dart'; +export 'src/model/auth/authentication_phone_identifier.dart'; +export 'src/model/auth/authentication_recaptcha.dart'; +export 'src/model/auth/authentication_third_party_identifier.dart'; +export 'src/model/auth/authentication_three_pid_creds.dart'; +export 'src/model/auth/authentication_token.dart'; +export 'src/model/auth/authentication_types.dart'; +export 'src/model/auth/authentication_user_identifier.dart'; export 'src/model/basic_event.dart'; export 'src/model/basic_event_with_sender.dart'; export 'src/model/basic_room_event.dart'; export 'src/model/event_types.dart'; +export 'src/model/events/forwarded_room_key_content.dart'; +export 'src/model/events/olm_plaintext_payload.dart'; +export 'src/model/events/room_encrypted_content.dart'; +export 'src/model/events/room_encryption_content.dart'; +export 'src/model/events/room_key_content.dart'; +export 'src/model/events/room_key_request_content.dart'; +export 'src/model/events/secret_storage_default_key_content.dart'; +export 'src/model/events/secret_storage_key_content.dart'; +export 'src/model/events/tombstone_content.dart'; export 'src/model/events_sync_update.dart'; export 'src/model/matrix_connection_exception.dart'; export 'src/model/matrix_event.dart'; @@ -53,22 +67,7 @@ export 'src/model/sync_update.dart'; export 'src/model/third_party_location.dart'; export 'src/model/third_party_user.dart'; export 'src/model/upload_key_signatures_response.dart'; -export 'src/model/auth/authentication_data.dart'; -export 'src/model/auth/authentication_identifier.dart'; -export 'src/model/auth/authentication_password.dart'; -export 'src/model/auth/authentication_phone_identifier.dart'; -export 'src/model/auth/authentication_recaptcha.dart'; -export 'src/model/auth/authentication_third_party_identifier.dart'; -export 'src/model/auth/authentication_three_pid_creds.dart'; -export 'src/model/auth/authentication_token.dart'; -export 'src/model/auth/authentication_types.dart'; -export 'src/model/auth/authentication_user_identifier.dart'; -export 'src/model/events/forwarded_room_key_content.dart'; -export 'src/model/events/olm_plaintext_payload.dart'; -export 'src/model/events/room_encrypted_content.dart'; -export 'src/model/events/room_encryption_content.dart'; -export 'src/model/events/room_key_content.dart'; -export 'src/model/events/room_key_request_content.dart'; -export 'src/model/events/secret_storage_default_key_content.dart'; -export 'src/model/events/secret_storage_key_content.dart'; -export 'src/model/events/tombstone_content.dart'; +export 'src/utils/logs.dart'; +export 'src/utils/map_copy_extension.dart'; +export 'src/utils/try_get_map_extension.dart'; +export 'src/values.dart'; diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index b1484441..88859870 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -29,6 +28,7 @@ import 'dart:typed_data'; import 'package:http/http.dart' as http; import '../matrix_api_lite.dart'; +import 'generated/api.dart'; import 'model/auth/authentication_data.dart'; import 'model/events_sync_update.dart'; import 'model/matrix_connection_exception.dart'; @@ -41,8 +41,6 @@ import 'model/third_party_location.dart'; import 'model/third_party_user.dart'; import 'model/upload_key_signatures_response.dart'; -import 'generated/api.dart'; - enum RequestType { GET, POST, PUT, DELETE } String describeEnum(Object enumEntry) { @@ -55,11 +53,13 @@ String describeEnum(Object enumEntry) { class MatrixApi extends Api { /// The homeserver this client is communicating with. Uri? get homeserver => baseUri; + set homeserver(Uri? uri) => baseUri = uri; /// This is the access token for the matrix client. When it is undefined, then /// the user needs to sign in first. String? get accessToken => bearerToken; + set accessToken(String? token) => bearerToken = token; @override diff --git a/lib/src/model/algorithm_types.dart b/lib/src/model/algorithm_types.dart index 59144cf3..e4f8548b 100644 --- a/lib/src/model/algorithm_types.dart +++ b/lib/src/model/algorithm_types.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/auth/authentication_data.dart b/lib/src/model/auth/authentication_data.dart index 85d39767..53ea3ecf 100644 --- a/lib/src/model/auth/authentication_data.dart +++ b/lib/src/model/auth/authentication_data.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -24,7 +23,7 @@ class AuthenticationData { String type; - String?/*?*//*?*/ session; + String? /*?*/ /*?*/ session; AuthenticationData({required this.type, this.session}); @@ -34,7 +33,7 @@ class AuthenticationData { Map toJson() { final data = {}; - if (type != null) data['type'] = type; + data['type'] = type; if (session != null) data['session'] = session; return data; } diff --git a/lib/src/model/auth/authentication_identifier.dart b/lib/src/model/auth/authentication_identifier.dart index 572932a0..ada4778a 100644 --- a/lib/src/model/auth/authentication_identifier.dart +++ b/lib/src/model/auth/authentication_identifier.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,10 +21,10 @@ * SOFTWARE. */ -import 'authentication_types.dart'; -import 'authentication_user_identifier.dart'; import 'authentication_phone_identifier.dart'; import 'authentication_third_party_identifier.dart'; +import 'authentication_types.dart'; +import 'authentication_user_identifier.dart'; class AuthenticationIdentifier { String type; diff --git a/lib/src/model/auth/authentication_password.dart b/lib/src/model/auth/authentication_password.dart index b1066c2f..2b5cb13a 100644 --- a/lib/src/model/auth/authentication_password.dart +++ b/lib/src/model/auth/authentication_password.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,11 +21,10 @@ * SOFTWARE. */ -import 'authentication_user_identifier.dart'; - import 'authentication_data.dart'; import 'authentication_identifier.dart'; import 'authentication_types.dart'; +import 'authentication_user_identifier.dart'; class AuthenticationPassword extends AuthenticationData { String? user; @@ -37,7 +35,10 @@ class AuthenticationPassword extends AuthenticationData { AuthenticationIdentifier identifier; AuthenticationPassword( - {String? session, required this.password, this.user, required this.identifier}) + {String? session, + required this.password, + this.user, + required this.identifier}) : super( type: AuthenticationTypes.password, session: session, diff --git a/lib/src/model/auth/authentication_phone_identifier.dart b/lib/src/model/auth/authentication_phone_identifier.dart index 5e3c7779..e6eb8aa6 100644 --- a/lib/src/model/auth/authentication_phone_identifier.dart +++ b/lib/src/model/auth/authentication_phone_identifier.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/auth/authentication_recaptcha.dart b/lib/src/model/auth/authentication_recaptcha.dart index fdedf5b3..20c8d3c2 100644 --- a/lib/src/model/auth/authentication_recaptcha.dart +++ b/lib/src/model/auth/authentication_recaptcha.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/auth/authentication_third_party_identifier.dart b/lib/src/model/auth/authentication_third_party_identifier.dart index 94b55e28..2860dfdf 100644 --- a/lib/src/model/auth/authentication_third_party_identifier.dart +++ b/lib/src/model/auth/authentication_third_party_identifier.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -29,7 +28,8 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier { String medium; String address; - AuthenticationThirdPartyIdentifier({required this.medium, required this.address}) + AuthenticationThirdPartyIdentifier( + {required this.medium, required this.address}) : super(type: AuthenticationIdentifierTypes.thirdParty); AuthenticationThirdPartyIdentifier.fromJson(Map json) diff --git a/lib/src/model/auth/authentication_three_pid_creds.dart b/lib/src/model/auth/authentication_three_pid_creds.dart index 2961ac56..8a20d904 100644 --- a/lib/src/model/auth/authentication_three_pid_creds.dart +++ b/lib/src/model/auth/authentication_three_pid_creds.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -31,7 +30,8 @@ import 'authentication_data.dart'; class AuthenticationThreePidCreds extends AuthenticationData { late List threepidCreds; - AuthenticationThreePidCreds({String? session, required String type, required this.threepidCreds}) + AuthenticationThreePidCreds( + {String? session, required String type, required this.threepidCreds}) : super( type: type, session: session, @@ -65,13 +65,16 @@ class AuthenticationThreePidCreds extends AuthenticationData { } class ThreepidCreds { - String/*!*/ sid; + String /*!*/ sid; String clientSecret; String idServer; String idAccessToken; ThreepidCreds( - {required this.sid, required this.clientSecret, required this.idServer, required this.idAccessToken}); + {required this.sid, + required this.clientSecret, + required this.idServer, + required this.idAccessToken}); ThreepidCreds.fromJson(Map json) : sid = json['sid'], diff --git a/lib/src/model/auth/authentication_token.dart b/lib/src/model/auth/authentication_token.dart index 63233f4f..13749069 100644 --- a/lib/src/model/auth/authentication_token.dart +++ b/lib/src/model/auth/authentication_token.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/auth/authentication_types.dart b/lib/src/model/auth/authentication_types.dart index 00f13793..ea181e40 100644 --- a/lib/src/model/auth/authentication_types.dart +++ b/lib/src/model/auth/authentication_types.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/auth/authentication_user_identifier.dart b/lib/src/model/auth/authentication_user_identifier.dart index 974f7fee..9070dc48 100644 --- a/lib/src/model/auth/authentication_user_identifier.dart +++ b/lib/src/model/auth/authentication_user_identifier.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/basic_event.dart b/lib/src/model/basic_event.dart index 666fa516..5ea833f1 100644 --- a/lib/src/model/basic_event.dart +++ b/lib/src/model/basic_event.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/basic_event_with_sender.dart b/lib/src/model/basic_event_with_sender.dart index 4b6114a7..6618fc5a 100644 --- a/lib/src/model/basic_event_with_sender.dart +++ b/lib/src/model/basic_event_with_sender.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -27,7 +26,11 @@ import 'basic_event.dart'; class BasicEventWithSender extends BasicEvent { String senderId; - BasicEventWithSender(); + BasicEventWithSender( + {required String type, + required Map content, + required this.senderId}) + : super(type: type, content: content); BasicEventWithSender.fromJson(Map json) : senderId = json['sender'], diff --git a/lib/src/model/basic_room_event.dart b/lib/src/model/basic_room_event.dart index 66eff7d8..0e416483 100644 --- a/lib/src/model/basic_room_event.dart +++ b/lib/src/model/basic_room_event.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/event_types.dart b/lib/src/model/event_types.dart index 19623f5d..d5adc9ac 100644 --- a/lib/src/model/event_types.dart +++ b/lib/src/model/event_types.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -68,6 +67,7 @@ abstract class EventTypes { static const String CrossSigningMasterKey = 'm.cross_signing.master'; static const String MegolmBackup = 'm.megolm_backup.v1'; static const String SecretStorageDefaultKey = 'm.secret_storage.default_key'; + static String secretStorageKey(String keyId) => 'm.secret_storage.key.$keyId'; // Spaces diff --git a/lib/src/model/events/forwarded_room_key_content.dart b/lib/src/model/events/forwarded_room_key_content.dart index fb8ca523..b4ec3232 100644 --- a/lib/src/model/events/forwarded_room_key_content.dart +++ b/lib/src/model/events/forwarded_room_key_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; import 'room_key_content.dart'; extension ForwardedRoomKeyContentBasicEventExtension on BasicEvent { @@ -35,12 +34,13 @@ class ForwardedRoomKeyContent extends RoomKeyContent { String senderKey; String senderClaimedEd25519Key; List forwardingCurve25519KeyChain; + ForwardedRoomKeyContent.fromJson(Map json) - : senderKey = json.tryGet('sender_key', ''), + : senderKey = json.tryGet('sender_key') ?? '', senderClaimedEd25519Key = - json.tryGet('sender_claimed_ed25519_key', ''), + json.tryGet('sender_claimed_ed25519_key') ?? '', forwardingCurve25519KeyChain = - json.tryGetList('forwarding_curve25519_key_chain', []), + json.tryGetList('forwarding_curve25519_key_chain') ?? [], super.fromJson(json); @override diff --git a/lib/src/model/events/olm_plaintext_payload.dart b/lib/src/model/events/olm_plaintext_payload.dart index 69a6d0e8..5f67ca1b 100644 --- a/lib/src/model/events/olm_plaintext_payload.dart +++ b/lib/src/model/events/olm_plaintext_payload.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -43,12 +42,12 @@ class OlmPlaintextPayload { factory OlmPlaintextPayload.fromJson(Map json) => OlmPlaintextPayload( - sender: json.tryGet('sender'), - type: json.tryGet('type'), - content: json.tryGetMap('content'), - recipient: json.tryGet('recipient'), - recipientKeys: json.tryGetMap('recipient_keys'), - keys: json.tryGetMap('keys'), + sender: json.tryGet('sender'), + type: json.tryGet('type'), + content: json.tryGetMap('content'), + recipient: json.tryGet('recipient'), + recipientKeys: json.tryGetMap('recipient_keys'), + keys: json.tryGetMap('keys'), ); Map toJson() { diff --git a/lib/src/model/events/room_encrypted_content.dart b/lib/src/model/events/room_encrypted_content.dart index 3608621a..e062f77f 100644 --- a/lib/src/model/events/room_encrypted_content.dart +++ b/lib/src/model/events/room_encrypted_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -24,8 +23,8 @@ import 'package:matrix_api_lite/src/utils/logs.dart'; -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension RoomEncryptedContentBasicEventExtension on BasicEvent { RoomEncryptedContent get parsedRoomEncryptedContent => @@ -41,18 +40,14 @@ class RoomEncryptedContent { Map? ciphertextOlm; RoomEncryptedContent.fromJson(Map json) - : algorithm = json.tryGet('algorithm', ''), - senderKey = json.tryGet('sender_key', ''), - deviceId = json.tryGet('device_id'), - sessionId = json.tryGet('session_id'), - ciphertextMegolm = json['ciphertext'] is String - ? json.tryGet('ciphertext') - : null, - ciphertextOlm = json['ciphertext'] is Map - ? json - .tryGet>('ciphertext') - ?.map((k, v) => MapEntry(k, CiphertextInfo.fromJson(v))) - : null; + : algorithm = json.tryGet('algorithm') ?? '', + senderKey = json.tryGet('sender_key') ?? '', + deviceId = json.tryGet('device_id'), + sessionId = json.tryGet('session_id'), + ciphertextMegolm = json.tryGet('ciphertext'), + ciphertextOlm = json + .tryGet>('ciphertext') + ?.map((k, v) => MapEntry(k, CiphertextInfo.fromJson(v))); Map toJson() { final data = {}; @@ -68,7 +63,8 @@ class RoomEncryptedContent { data['ciphertext'] = ciphertextMegolm; } if (ciphertextOlm != null) { - data['ciphertext'] = ciphertextOlm!.map((k, v) => MapEntry(k, v.toJson())); + data['ciphertext'] = + ciphertextOlm!.map((k, v) => MapEntry(k, v.toJson())); if (ciphertextMegolm != null) { Logs().wtf( 'ciphertextOlm and ciphertextMegolm are both set, which should never happen!'); @@ -83,17 +79,13 @@ class CiphertextInfo { int type; CiphertextInfo.fromJson(Map json) - : body = json.tryGet('body'), - type = json.tryGet('type'); + : body = json['body'], + type = json['type']; Map toJson() { final data = {}; - if (body != null) { - data['body'] = body; - } - if (type != null) { - data['type'] = type; - } + data['body'] = body; + data['type'] = type; return data; } } diff --git a/lib/src/model/events/room_encryption_content.dart b/lib/src/model/events/room_encryption_content.dart index c639ba67..b88db983 100644 --- a/lib/src/model/events/room_encryption_content.dart +++ b/lib/src/model/events/room_encryption_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension RoomEncryptionContentBasicEventExtension on BasicEvent { RoomEncryptionContent get parsedRoomEncryptionContent => @@ -36,9 +35,9 @@ class RoomEncryptionContent { int? rotationPeriodMsgs; RoomEncryptionContent.fromJson(Map json) - : algorithm = json.tryGet('algorithm', ''), - rotationPeriodMs = json.tryGet('rotation_period_ms'), - rotationPeriodMsgs = json.tryGet('rotation_period_msgs'); + : algorithm = json.tryGet('algorithm') ?? '', + rotationPeriodMs = json.tryGet('rotation_period_ms'), + rotationPeriodMsgs = json.tryGet('rotation_period_msgs'); Map toJson() { final data = {}; diff --git a/lib/src/model/events/room_key_content.dart b/lib/src/model/events/room_key_content.dart index 4149ffad..e179e662 100644 --- a/lib/src/model/events/room_key_content.dart +++ b/lib/src/model/events/room_key_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension RoomKeyContentBasicEventExtension on BasicEvent { RoomKeyContent get parsedRoomKeyContent => RoomKeyContent.fromJson(content); @@ -35,13 +34,17 @@ class RoomKeyContent { String sessionId; String sessionKey; - RoomKeyContent(); + RoomKeyContent( + {required this.algorithm, + required this.roomId, + required this.sessionId, + required this.sessionKey}); RoomKeyContent.fromJson(Map json) - : algorithm = json.tryGet('algorithm', ''), - roomId = json.tryGet('room_id', ''), - sessionId = json.tryGet('session_id', ''), - sessionKey = json.tryGet('session_key', ''); + : algorithm = json.tryGet('algorithm') ?? '', + roomId = json.tryGet('room_id') ?? '', + sessionId = json.tryGet('session_id') ?? '', + sessionKey = json.tryGet('session_key') ?? ''; Map toJson() { final data = {}; diff --git a/lib/src/model/events/room_key_request_content.dart b/lib/src/model/events/room_key_request_content.dart index 1a7e6871..394d8233 100644 --- a/lib/src/model/events/room_key_request_content.dart +++ b/lib/src/model/events/room_key_request_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension RoomKeyRequestContentBasicEventExtension on BasicEvent { RoomKeyRequestContent get parsedRoomKeyRequestContent => @@ -37,11 +36,11 @@ class RoomKeyRequestContent { String requestId; RoomKeyRequestContent.fromJson(Map json) - : body = RequestedKeyInfo.fromJson( + : body = ((x) => x != null ? RequestedKeyInfo.fromJson(x) : null)( json.tryGet>('body')), - action = json.tryGet('action', ''), - requestingDeviceId = json.tryGet('requesting_device_id', ''), - requestId = json.tryGet('request_id', ''); + action = json.tryGet('action') ?? '', + requestingDeviceId = json.tryGet('requesting_device_id') ?? '', + requestId = json.tryGet('request_id') ?? ''; Map toJson() { final data = {}; @@ -59,17 +58,17 @@ class RequestedKeyInfo { String sessionId; String senderKey; - RequestedKeyInfo(); + RequestedKeyInfo( + {required this.algorithm, + required this.roomId, + required this.sessionId, + required this.senderKey}); - factory RequestedKeyInfo.fromJson(Map json) { - if (json == null) return null; - final requestKeyInfo = RequestedKeyInfo(); - requestKeyInfo.algorithm = json.tryGet('algorithm', ''); - requestKeyInfo.roomId = json.tryGet('room_id', ''); - requestKeyInfo.sessionId = json.tryGet('session_id', ''); - requestKeyInfo.senderKey = json.tryGet('sender_key', ''); - return requestKeyInfo; - } + RequestedKeyInfo.fromJson(Map json) + : algorithm = json.tryGet('algorithm') ?? '', + roomId = json.tryGet('room_id') ?? '', + sessionId = json.tryGet('session_id') ?? '', + senderKey = json.tryGet('sender_key') ?? ''; Map toJson() { final data = {}; diff --git a/lib/src/model/events/secret_storage_default_key_content.dart b/lib/src/model/events/secret_storage_default_key_content.dart index 389795d0..46394fbf 100644 --- a/lib/src/model/events/secret_storage_default_key_content.dart +++ b/lib/src/model/events/secret_storage_default_key_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension SecretStorageDefaultKeyContentBasicEventExtension on BasicEvent { SecretStorageDefaultKeyContent get parsedSecretStorageDefaultKeyContent => @@ -31,9 +30,10 @@ extension SecretStorageDefaultKeyContentBasicEventExtension on BasicEvent { } class SecretStorageDefaultKeyContent { - String key; + //TODO: Required by spec, we should require it here and make sure to catch it everywhere + String? key; - SecretStorageDefaultKeyContent(); + SecretStorageDefaultKeyContent({required this.key}); SecretStorageDefaultKeyContent.fromJson(Map json) : key = json.tryGet('key'); diff --git a/lib/src/model/events/secret_storage_key_content.dart b/lib/src/model/events/secret_storage_key_content.dart index 8e10a182..b6542bac 100644 --- a/lib/src/model/events/secret_storage_key_content.dart +++ b/lib/src/model/events/secret_storage_key_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension SecretStorageKeyContentBasicEventExtension on BasicEvent { SecretStorageKeyContent get parsedSecretStorageKeyContent => @@ -42,9 +41,9 @@ class SecretStorageKeyContent { : passphrase = json['passphrase'] is Map ? PassphraseInfo.fromJson(json['passphrase']) : null, - iv = json.tryGet('iv'), - mac = json.tryGet('mac'), - algorithm = json.tryGet('algorithm'); + iv = json.tryGet('iv'), + mac = json.tryGet('mac'), + algorithm = json.tryGet('algorithm'); Map toJson() { final data = {}; @@ -57,24 +56,30 @@ class SecretStorageKeyContent { } class PassphraseInfo { - String algorithm; - String salt; - int iterations; + //TODO: algorithm, salt, iterations are required by spec, + //TODO: we should require it here and make sure to catch it everywhere + String? algorithm; + String? salt; + int? iterations; int? bits; - PassphraseInfo(); + PassphraseInfo( + {required this.algorithm, + required this.salt, + required this.iterations, + this.bits}); PassphraseInfo.fromJson(Map json) - : algorithm = json.tryGet('algorithm'), - salt = json.tryGet('salt'), - iterations = json.tryGet('iterations'), + : algorithm = json.tryGet('algorithm'), + salt = json.tryGet('salt'), + iterations = json.tryGet('iterations'), bits = json.tryGet('bits'); Map toJson() { final data = {}; - if (algorithm != null) data['algorithm'] = algorithm; - if (salt != null) data['salt'] = salt; - if (iterations != null) data['iterations'] = iterations; + data['algorithm'] = algorithm; + data['salt'] = salt; + data['iterations'] = iterations; if (bits != null) data['bits'] = bits; return data; } diff --git a/lib/src/model/events/tombstone_content.dart b/lib/src/model/events/tombstone_content.dart index 93a8221f..18804448 100644 --- a/lib/src/model/events/tombstone_content.dart +++ b/lib/src/model/events/tombstone_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,8 +21,8 @@ * SOFTWARE. */ -import '../basic_event.dart'; import '../../utils/try_get_map_extension.dart'; +import '../basic_event.dart'; extension TombstoneContentBasicEventExtension on BasicEvent { TombstoneContent get parsedTombstoneContent => @@ -35,8 +34,8 @@ class TombstoneContent { String replacementRoom; TombstoneContent.fromJson(Map json) - : body = json.tryGet('body', ''), - replacementRoom = json.tryGet('replacement_room', ''); + : body = json.tryGet('body') ?? '', + replacementRoom = json.tryGet('replacement_room') ?? ''; Map toJson() { final data = {}; diff --git a/lib/src/model/events_sync_update.dart b/lib/src/model/events_sync_update.dart index a93ee5b3..2f35ac74 100644 --- a/lib/src/model/events_sync_update.dart +++ b/lib/src/model/events_sync_update.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/matrix_connection_exception.dart b/lib/src/model/matrix_connection_exception.dart index 96d12af9..97194f64 100644 --- a/lib/src/model/matrix_connection_exception.dart +++ b/lib/src/model/matrix_connection_exception.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -25,6 +24,7 @@ class MatrixConnectionException implements Exception { final dynamic original; final StackTrace stackTrace; + MatrixConnectionException(this.original, this.stackTrace); @override diff --git a/lib/src/model/matrix_event.dart b/lib/src/model/matrix_event.dart index b54856db..516f4b35 100644 --- a/lib/src/model/matrix_event.dart +++ b/lib/src/model/matrix_event.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,18 +21,33 @@ * SOFTWARE. */ -import 'stripped_state_event.dart'; import '../utils/map_copy_extension.dart'; +import 'stripped_state_event.dart'; class MatrixEvent extends StrippedStateEvent { String eventId; String? roomId; - late DateTime originServerTs; + DateTime originServerTs; Map? unsigned; Map? prevContent; String? redacts; - MatrixEvent(); + MatrixEvent({ + required String type, + required Map content, + required String senderId, + String? stateKey, + required this.eventId, + this.roomId, + required this.originServerTs, + this.unsigned, + this.prevContent, + this.redacts, + }) : super( + type: type, + content: content, + senderId: senderId, + stateKey: stateKey); MatrixEvent.fromJson(Map json) : eventId = json['event_id'], diff --git a/lib/src/model/matrix_exception.dart b/lib/src/model/matrix_exception.dart index f2a03e24..3e7ef751 100644 --- a/lib/src/model/matrix_exception.dart +++ b/lib/src/model/matrix_exception.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -62,7 +61,9 @@ class MatrixException implements Exception { /// The frozen request which triggered this Error http.Response? response; - MatrixException(Response this.response) : raw = json.decode(response.body); + MatrixException(http.Response this.response) + : raw = json.decode(response.body); + MatrixException.fromJson(Map content) : raw = content; @override @@ -87,7 +88,7 @@ class MatrixException implements Exception { /// For each endpoint, a server offers one or more 'flows' that the client can use /// to authenticate itself. Each flow comprises a series of stages. If this request /// doesn't need additional authentication, then this is null. - List?/*?*/ get authenticationFlows { + List? get authenticationFlows { if (!raw.containsKey('flows') || !(raw['flows'] is List)) return null; return (raw['flows'] as List) .map((flow) => flow['stages']) @@ -110,5 +111,6 @@ class MatrixException implements Exception { /// to authenticate itself. Each flow comprises a series of stages class AuthenticationFlow { final List stages; + const AuthenticationFlow(this.stages); } diff --git a/lib/src/model/matrix_keys.dart b/lib/src/model/matrix_keys.dart index 2ad89ed1..01c0538a 100644 --- a/lib/src/model/matrix_keys.dart +++ b/lib/src/model/matrix_keys.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -24,15 +23,16 @@ import '../utils/map_copy_extension.dart'; -class MatrixSignableKey { +abstract class MatrixSignableKey { String userId; - String? identifier; + + String? get identifier; + Map keys; Map>? signatures; Map? unsigned; - MatrixSignableKey(this.userId, this.identifier, this.keys, this.signatures, - {this.unsigned}); + MatrixSignableKey(this.userId, this.keys, this.signatures, {this.unsigned}); // This object is used for signing so we need the raw json too Map? _json; @@ -65,6 +65,7 @@ class MatrixSignableKey { class MatrixCrossSigningKey extends MatrixSignableKey { List usage; + String? get publicKey => identifier; MatrixCrossSigningKey( @@ -73,14 +74,15 @@ class MatrixCrossSigningKey extends MatrixSignableKey { Map keys, Map> signatures, { Map? unsigned, - }) : super(userId, keys?.values?.first, keys, signatures, unsigned: unsigned); + }) : super(userId, keys, signatures, unsigned: unsigned); + + @override + String? get identifier => keys.values.first; @override MatrixCrossSigningKey.fromJson(Map json) - : super.fromJson(json) { - usage = List.from(json['usage']); - identifier = keys?.values?.first; - } + : usage = List.from(json['usage']), + super.fromJson(json); @override Map toJson() { @@ -91,25 +93,29 @@ class MatrixCrossSigningKey extends MatrixSignableKey { } class MatrixDeviceKeys extends MatrixSignableKey { - String get deviceId => identifier!; + String deviceId; List algorithms; + String? get deviceDisplayName => unsigned != null ? unsigned!['device_display_name'] : null; MatrixDeviceKeys( String userId, - String deviceId, + this.deviceId, this.algorithms, Map keys, Map> signatures, { Map? unsigned, - }) : super(userId, deviceId, keys, signatures, unsigned: unsigned); + }) : super(userId, keys, signatures, unsigned: unsigned); @override - MatrixDeviceKeys.fromJson(Map json) : super.fromJson(json) { - identifier = json['device_id']; - algorithms = json['algorithms'].cast(); - } + String? get identifier => deviceId; + + @override + MatrixDeviceKeys.fromJson(Map json) + : algorithms = json['algorithms'].cast(), + deviceId = json['device_id'], + super.fromJson(json); @override Map toJson() { diff --git a/lib/src/model/message_types.dart b/lib/src/model/message_types.dart index e6cbc443..d6745350 100644 --- a/lib/src/model/message_types.dart +++ b/lib/src/model/message_types.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/presence.dart b/lib/src/model/presence.dart index 4874ea54..73848c2e 100644 --- a/lib/src/model/presence.dart +++ b/lib/src/model/presence.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/presence_content.dart b/lib/src/model/presence_content.dart index 0df3f0c2..edf9a1de 100644 --- a/lib/src/model/presence_content.dart +++ b/lib/src/model/presence_content.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/request_token_response.dart b/lib/src/model/request_token_response.dart index 46f24e5c..4be5d726 100644 --- a/lib/src/model/request_token_response.dart +++ b/lib/src/model/request_token_response.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/room_creation_types.dart b/lib/src/model/room_creation_types.dart index be7b75d9..703f0ce1 100644 --- a/lib/src/model/room_creation_types.dart +++ b/lib/src/model/room_creation_types.dart @@ -1,4 +1,3 @@ - abstract class RoomCreationTypes { static const String mSpace = 'm.space'; } diff --git a/lib/src/model/room_keys_keys.dart b/lib/src/model/room_keys_keys.dart index b285c454..39df80b4 100644 --- a/lib/src/model/room_keys_keys.dart +++ b/lib/src/model/room_keys_keys.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -53,9 +52,7 @@ class RoomKeysSingleKey { class RoomKeysRoom { Map sessions; - RoomKeysRoom({required this.sessions}) { - sessions ??= {}; - } + RoomKeysRoom({required this.sessions}); RoomKeysRoom.fromJson(Map json) : sessions = (json['sessions'] as Map) diff --git a/lib/src/model/room_summary.dart b/lib/src/model/room_summary.dart index 74dded00..1947d829 100644 --- a/lib/src/model/room_summary.dart +++ b/lib/src/model/room_summary.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -26,6 +25,7 @@ class RoomSummary { List? mHeroes; int? mJoinedMemberCount; int? mInvitedMemberCount; + RoomSummary.fromJson(Map json) : mHeroes = json['m.heroes'] != null ? List.from(json['m.heroes']) diff --git a/lib/src/model/room_types.dart b/lib/src/model/room_types.dart index 7dbcf0f5..ba551ae9 100644 --- a/lib/src/model/room_types.dart +++ b/lib/src/model/room_types.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/stripped_state_event.dart b/lib/src/model/stripped_state_event.dart index cb8f914d..20bd4927 100644 --- a/lib/src/model/stripped_state_event.dart +++ b/lib/src/model/stripped_state_event.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -27,7 +26,13 @@ import 'basic_event_with_sender.dart'; class StrippedStateEvent extends BasicEventWithSender { String? stateKey; - StrippedStateEvent(); + StrippedStateEvent( + {required String type, + required Map content, + required String senderId, + this.stateKey}) + : super(type: type, content: content, senderId: senderId); + StrippedStateEvent.fromJson(Map json) : stateKey = json['state_key'], super.fromJson(json); diff --git a/lib/src/model/supported_protocol.dart b/lib/src/model/supported_protocol.dart index 32cba75c..0f1fcf50 100644 --- a/lib/src/model/supported_protocol.dart +++ b/lib/src/model/supported_protocol.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -45,9 +44,7 @@ class SupportedProtocol { data['location_fields'] = locationFields; data['icon'] = icon; data['field_types'] = fieldTypes.map((k, v) => MapEntry(k, v.toJson())); - data['instances'] = instances.map((v) => v.toJson()).toList(); - return data; } } @@ -56,10 +53,9 @@ class ProtocolFieldType { String regexp; String placeholder; - ProtocolFieldType.fromJson(Map json) { - regexp = json['regexp']; - placeholder = json['placeholder']; - } + ProtocolFieldType.fromJson(Map json) + : regexp = json['regexp'], + placeholder = json['placeholder']; Map toJson() { final data = {}; @@ -75,12 +71,11 @@ class ProtocolInstance { String? icon; dynamic fields; - ProtocolInstance.fromJson(Map json) { - networkId = json['network_id']; - desc = json['desc']; - icon = json['icon']; - fields = json['fields']; - } + ProtocolInstance.fromJson(Map json) + : networkId = json['network_id'], + desc = json['desc'], + icon = json['icon'], + fields = json['fields']; Map toJson() { final data = {}; diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index 5b93d1ef..878b9343 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -40,7 +39,7 @@ class SyncUpdate { Map? deviceOneTimeKeysCount; List? deviceUnusedFallbackKeyTypes; - SyncUpdate(); + SyncUpdate({required this.nextBatch}); SyncUpdate.fromJson(Map json) : nextBatch = json['next_batch'], @@ -136,6 +135,7 @@ class RoomsUpdate { .map((k, v) => MapEntry(k, LeftRoomUpdate.fromJson(v))) : null; } + Map toJson() { final data = {}; if (join != null) { @@ -224,6 +224,7 @@ class JoinedRoomUpdate extends SyncRoomUpdate { class InvitedRoomUpdate extends SyncRoomUpdate { List? inviteState; + InvitedRoomUpdate.fromJson(Map json) { inviteState = (json['invite_state'] != null && json['invite_state']['events'] != null) @@ -232,6 +233,7 @@ class InvitedRoomUpdate extends SyncRoomUpdate { .toList() : null; } + Map toJson() { final data = {}; if (inviteState != null) { @@ -266,6 +268,7 @@ class LeftRoomUpdate extends SyncRoomUpdate { .toList() : null; } + Map toJson() { final data = {}; if (state != null) { @@ -318,10 +321,12 @@ class TimelineUpdate { class UnreadNotificationCounts { int? highlightCount; int? notificationCount; + UnreadNotificationCounts.fromJson(Map json) { highlightCount = json['highlight_count']; notificationCount = json['notification_count']; } + Map toJson() { final data = {}; if (highlightCount != null) { @@ -337,10 +342,12 @@ class UnreadNotificationCounts { class DeviceListsUpdate { List? changed; List? left; + DeviceListsUpdate.fromJson(Map json) { changed = List.from(json['changed'] ?? []); left = List.from(json['left'] ?? []); } + Map toJson() { final data = {}; if (changed != null) { diff --git a/lib/src/model/third_party_location.dart b/lib/src/model/third_party_location.dart index fb834daf..a2271f9b 100644 --- a/lib/src/model/third_party_location.dart +++ b/lib/src/model/third_party_location.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/third_party_user.dart b/lib/src/model/third_party_user.dart index e230e4ab..a4289b2a 100644 --- a/lib/src/model/third_party_user.dart +++ b/lib/src/model/third_party_user.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/model/upload_key_signatures_response.dart b/lib/src/model/upload_key_signatures_response.dart index 94f3255f..38bf3774 100644 --- a/lib/src/model/upload_key_signatures_response.dart +++ b/lib/src/model/upload_key_signatures_response.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/utils/logs.dart b/lib/src/utils/logs.dart index 105319a3..37852945 100644 --- a/lib/src/utils/logs.dart +++ b/lib/src/utils/logs.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/utils/map_copy_extension.dart b/lib/src/utils/map_copy_extension.dart index d2b89720..2cf95989 100644 --- a/lib/src/utils/map_copy_extension.dart +++ b/lib/src/utils/map_copy_extension.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/lib/src/utils/try_get_map_extension.dart b/lib/src/utils/try_get_map_extension.dart index 0024aa12..d768a24d 100644 --- a/lib/src/utils/try_get_map_extension.dart +++ b/lib/src/utils/try_get_map_extension.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -25,60 +24,45 @@ import 'logs.dart'; extension TryGetMapExtension on Map { - T tryGet(String key, [T fallbackValue]) { + T? tryGet(String key) { final value = this[key]; if (value != null && !(value is T)) { Logs().w( 'Expected "${T.runtimeType}" in event content for the Key "$key" but got "${value.runtimeType}".'); - return fallbackValue; - } - if (value == null && fallbackValue != null) { - Logs().w( - 'Required field in event content for the Key "$key" is null. Set to "$fallbackValue".'); - return fallbackValue; + return null; } return value; } - List tryGetList(String key, [List fallbackValue]) { + List? tryGetList(String key) { final value = this[key]; if (value != null && !(value is List)) { Logs().w( 'Expected "List<${T.runtimeType}>" in event content for the key "$key" but got "${value.runtimeType}".'); - return fallbackValue; - } - if (value == null && fallbackValue != null) { - Logs().w( - 'Required field in event content for the key "$key" is null. Set to "$fallbackValue".'); - return fallbackValue; + return null; } try { return (value as List).cast(); } catch (_) { Logs().w( 'Unable to create "List<${T.runtimeType}>" in event content for the key "$key"'); - return fallbackValue; + return null; } } - Map tryGetMap(String key, [Map fallbackValue]) { + Map? tryGetMap(String key) { final value = this[key]; if (value != null && !(value is Map)) { Logs().w( 'Expected "Map<${A.runtimeType},${B.runtimeType}>" in event content for the key "$key" but got "${value.runtimeType}".'); - return fallbackValue; - } - if (value == null && fallbackValue != null) { - Logs().w( - 'Required field in event content for the key "$key" is null. Set to "$fallbackValue".'); - return fallbackValue; + return null; } try { return (value as Map).cast(); } catch (_) { Logs().w( 'Unable to create "Map<${A.runtimeType},${B.runtimeType}>" in event content for the key "$key"'); - return fallbackValue; + return null; } } } diff --git a/lib/src/values.dart b/lib/src/values.dart index b7f1c0c5..aa4f66ac 100644 --- a/lib/src/values.dart +++ b/lib/src/values.dart @@ -14,6 +14,7 @@ class TagType { static final favourite = 'm.favourite'; static final lowPriority = 'm.lowpriority'; static final serverNotice = 'm.server_notice'; + static bool isValid(String tag) => tag.startsWith('m.') ? [favourite, lowPriority, serverNotice].contains(tag) : true; diff --git a/test/event_content_test.dart b/test/event_content_test.dart index d7f79670..82099ac7 100644 --- a/test/event_content_test.dart +++ b/test/event_content_test.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH @@ -22,9 +21,10 @@ * SOFTWARE. */ +import 'dart:convert'; + import 'package:matrix_api_lite/matrix_api_lite.dart'; import 'package:test/test.dart'; -import 'dart:convert'; void main() { group('Event Content tests', () { diff --git a/test/map_copy_extension_test.dart b/test/map_copy_extension_test.dart index f67b60fc..329771d9 100644 --- a/test/map_copy_extension_test.dart +++ b/test/map_copy_extension_test.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 97b454e4..54a8f0a8 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -1,18 +1,17 @@ - /* MIT License -* +* * Copyright (C) 2019, 2020, 2021 Famedly GmbH -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,6 +22,7 @@ */ import 'dart:typed_data'; + import 'package:matrix_api_lite/fake_matrix_api.dart'; import 'package:matrix_api_lite/matrix_api_lite.dart'; import 'package:test/test.dart'; @@ -60,8 +60,8 @@ void main() { 'session': 'xxxxxxyz', 'completed': ['example.type.foo'] }); - expect( - exception.authenticationFlows!.first.stages.first, 'example.type.foo'); + expect(exception.authenticationFlows!.first.stages.first, + 'example.type.foo'); expect(exception.authenticationParams!['example.type.baz'], {'example_key': 'foobar'}); expect(exception.session, 'xxxxxxyz'); @@ -111,10 +111,8 @@ void main() { expect((exception as MatrixException).errcode, 'M_FORBIDDEN'); expect(exception.error, MatrixError.M_FORBIDDEN); expect(exception.errorMessage, 'Blabla'); - expect(exception.requireAdditionalAuthentication, - false); - expect( - exception.toString(), 'M_FORBIDDEN: Blabla'); + expect(exception.requireAdditionalAuthentication, false); + expect(exception.toString(), 'M_FORBIDDEN: Blabla'); error = true; } expect(error, true); @@ -146,10 +144,10 @@ void main() { }); test('getLoginTypes', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); - final loginTypes = await (matrixApi.getLoginFlows() as FutureOr>); - expect(loginTypes.first.type, 'm.login.password'); + final loginTypes = await matrixApi.getLoginFlows(); + expect(loginTypes?.first.type, 'm.login.password'); expect(FakeMatrixApi.api['GET']!['/client/r0/login']({}), - {'flows': loginTypes.map((x) => x.toJson()).toList()}); + {'flows': loginTypes?.map((x) => x.toJson()).toList()}); matrixApi.homeserver = null; }); test('login', () async { @@ -194,8 +192,8 @@ void main() { idAccessToken: '1234', ); expect( - FakeMatrixApi.api['POST']! - ['/client/r0/register/email/requestToken']({}), + FakeMatrixApi + .api['POST']!['/client/r0/register/email/requestToken']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -212,8 +210,8 @@ void main() { idAccessToken: '1234', ); expect( - FakeMatrixApi.api['POST']! - ['/client/r0/register/email/requestToken']({}), + FakeMatrixApi + .api['POST']!['/client/r0/register/email/requestToken']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -281,9 +279,9 @@ void main() { test('getThirdPartyIdentifiers', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final response = await (matrixApi.getAccount3PIDs() as FutureOr>); + final response = await matrixApi.getAccount3PIDs(); expect(FakeMatrixApi.api['GET']!['/client/r0/account/3pid']({}), - {'threepids': response.map((t) => t.toJson()).toList()}); + {'threepids': response?.map((t) => t.toJson()).toList()}); matrixApi.homeserver = matrixApi.accessToken = null; }); test('addThirdPartyIdentifier', () async { @@ -537,13 +535,13 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final states = await (matrixApi.getMembersByRoom( + final states = await matrixApi.getMembersByRoom( '!localpart:server.abc', at: '1234', membership: Membership.join, notMembership: Membership.leave, - ) as FutureOr>); - expect(states.length, 1); + ); + expect(states?.length, 1); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -551,11 +549,11 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final states = await (matrixApi.getJoinedMembersByRoom( + final states = await matrixApi.getJoinedMembersByRoom( '!localpart:server.abc', - ) as FutureOr>); - expect(states.length, 1); - expect(states['@bar:example.com']!.toJson(), { + ); + expect(states?.length, 1); + expect(states?['@bar:example.com']?.toJson(), { 'display_name': 'Bar', 'avatar_url': 'mxc://riot.ovh/printErCATzZijQsSDWorRaK' }); @@ -667,8 +665,8 @@ void main() { ); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/directory/room/%23testalias%3Aexample.com']({}), + FakeMatrixApi.api['GET']![ + '/client/r0/directory/room/%23testalias%3Aexample.com']({}), roomAliasInformation.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -851,8 +849,8 @@ void main() { ); expect( - FakeMatrixApi.api['POST']! - ['/client/r0/publicRooms?server=example.com']({}), + FakeMatrixApi + .api['POST']!['/client/r0/publicRooms?server=example.com']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -913,8 +911,8 @@ void main() { final response = await matrixApi.getUserProfile('@alice:example.com'); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/profile/%40alice%3Aexample.com']({}), + FakeMatrixApi + .api['GET']!['/client/r0/profile/%40alice%3Aexample.com']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1017,8 +1015,8 @@ void main() { ts: 10, ); expect( - FakeMatrixApi.api['GET']! - ['/media/r0/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), + FakeMatrixApi.api['GET']![ + '/media/r0/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), openGraphData.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1048,9 +1046,9 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final devices = await (matrixApi.getDevices() as FutureOr>); + final devices = await matrixApi.getDevices(); expect(FakeMatrixApi.api['GET']!['/client/r0/devices']({})['devices'], - devices.map((i) => i.toJson()).toList()); + devices?.map((i) => i.toJson()).toList()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -1117,12 +1115,12 @@ void main() { token: '1234', ); expect( - response - .deviceKeys!['@alice:example.com']!['JLAFKJWSCS']!.deviceDisplayName, + response.deviceKeys!['@alice:example.com']!['JLAFKJWSCS']! + .deviceDisplayName, 'Alices mobile phone'); expect( - FakeMatrixApi.api['POST']! - ['/client/r0/keys/query']({'device_keys': {}}), + FakeMatrixApi + .api['POST']!['/client/r0/keys/query']({'device_keys': {}}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1242,10 +1240,10 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final response = await (matrixApi.getPushers() as FutureOr>); + final response = await matrixApi.getPushers(); expect( FakeMatrixApi.api['GET']!['/client/r0/pushers']({}), - {'pushers': response.map((i) => i.toJson()).toList()}, + {'pushers': response?.map((i) => i.toJson()).toList()}, ); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1281,8 +1279,8 @@ void main() { only: '1234', ); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/notifications?from=1234&limit=10&only=1234']({}), + FakeMatrixApi.api['GET']![ + '/client/r0/notifications?from=1234&limit=10&only=1234']({}), response.toJson(), ); @@ -1307,8 +1305,8 @@ void main() { final response = await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/pushrules/global/content/nocake']({}), + FakeMatrixApi + .api['GET']!['/client/r0/pushrules/global/content/nocake']({}), response.toJson(), ); @@ -1407,8 +1405,8 @@ void main() { final response = await matrixApi.getEvents(from: '1234', roomId: '!1234', timeout: 10); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/events?from=1234&timeout=10&roomId=%211234']({}), + FakeMatrixApi.api['GET']![ + '/client/r0/events?from=1234&timeout=10&roomId=%211234']({}), response.toJson(), ); @@ -1418,12 +1416,12 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; - final response = await (matrixApi.getRoomTags( - '@alice:example.com', '!localpart:example.com') as FutureOr>); + final response = await matrixApi.getRoomTags( + '@alice:example.com', '!localpart:example.com'); expect( FakeMatrixApi.api['GET']![ '/client/r0/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']({}), - {'tags': response.map((k, v) => MapEntry(k, v.toJson()))}, + {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, ); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1507,8 +1505,8 @@ void main() { final response = await matrixApi.getWhoIs('@alice:example.com'); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/admin/whois/%40alice%3Aexample.com']({}), + FakeMatrixApi + .api['GET']!['/client/r0/admin/whois/%40alice%3Aexample.com']({}), response.toJson(), ); @@ -1521,8 +1519,8 @@ void main() { final response = await matrixApi.getEventContext('1234', '1234', limit: 10, filter: '{}'); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), + FakeMatrixApi.api['GET']![ + '/client/r0/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), response.toJson(), ); @@ -1596,8 +1594,8 @@ void main() { final response = await matrixApi.requestThirdPartyLocationsByAlias('1234'); expect( - FakeMatrixApi.api['GET']! - ['/client/r0/thirdparty/location?alias=1234']({}), + FakeMatrixApi + .api['GET']!['/client/r0/thirdparty/location?alias=1234']({}), response.map((i) => i.toJson()).toList(), ); @@ -1621,8 +1619,8 @@ void main() { final response = await matrixApi.requestOpenIdToken('1234', {}); expect( - FakeMatrixApi.api['POST']! - ['/client/r0/user/1234/openid/request_token']({}), + FakeMatrixApi + .api['POST']!['/client/r0/user/1234/openid/request_token']({}), response.toJson(), ); @@ -1647,8 +1645,8 @@ void main() { }; final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); expect( - FakeMatrixApi.api['POST']! - ['/client/unstable/room_keys/version']({})['version'], + FakeMatrixApi.api['POST']!['/client/unstable/room_keys/version']( + {})['version'], ret); }); test('getRoomKeysVersionCurrent', () async { @@ -1656,7 +1654,8 @@ void main() { matrixApi.accessToken = '1234'; final ret = await matrixApi.getRoomKeysVersionCurrent(); - expect(FakeMatrixApi.api['GET']!['/client/unstable/room_keys/version']({}), + expect( + FakeMatrixApi.api['GET']!['/client/unstable/room_keys/version']({}), ret.toJson()); }); test('putRoomKeysVersion', () async { @@ -1801,8 +1800,8 @@ void main() { }); final ret = await matrixApi.postRoomKeysKey('5', session); expect( - FakeMatrixApi.api['PUT']! - ['/client/unstable/room_keys/keys?version=5']({}), + FakeMatrixApi + .api['PUT']!['/client/unstable/room_keys/keys?version=5']({}), ret.toJson()); }); test('getRoomKeys', () async { @@ -1811,8 +1810,8 @@ void main() { final ret = await matrixApi.getRoomKeys('5'); expect( - FakeMatrixApi.api['GET']! - ['/client/unstable/room_keys/keys?version=5']({}), + FakeMatrixApi + .api['GET']!['/client/unstable/room_keys/keys?version=5']({}), ret.toJson()); }); test('deleteRoomKeys', () async { @@ -1821,8 +1820,8 @@ void main() { final ret = await matrixApi.deleteRoomKeys('5'); expect( - FakeMatrixApi.api['DELETE']! - ['/client/unstable/room_keys/keys?version=5']({}), + FakeMatrixApi + .api['DELETE']!['/client/unstable/room_keys/keys?version=5']({}), ret.toJson()); }); test('AuthenticationData', () { diff --git a/test/try_get_map_extension_test.dart b/test/try_get_map_extension_test.dart index 43317512..d38a1e68 100644 --- a/test/try_get_map_extension_test.dart +++ b/test/try_get_map_extension_test.dart @@ -1,4 +1,3 @@ - /* MIT License * * Copyright (C) 2019, 2020, 2021 Famedly GmbH