null safety cleanup
This commit is contained in:
parent
9e6019b820
commit
1a51f813a7
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (type != null) data['type'] = type;
|
||||
data['type'] = type;
|
||||
if (session != null) data['session'] = session;
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
|
|
|
|||
|
|
@ -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> 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<String, dynamic> json)
|
||||
: sid = json['sid'],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> content,
|
||||
required this.senderId})
|
||||
: super(type: type, content: content);
|
||||
|
||||
BasicEventWithSender.fromJson(Map<String, dynamic> json)
|
||||
: senderId = json['sender'],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<String> forwardingCurve25519KeyChain;
|
||||
|
||||
ForwardedRoomKeyContent.fromJson(Map<String, dynamic> json)
|
||||
: senderKey = json.tryGet<String>('sender_key', ''),
|
||||
: senderKey = json.tryGet('sender_key') ?? '',
|
||||
senderClaimedEd25519Key =
|
||||
json.tryGet<String>('sender_claimed_ed25519_key', ''),
|
||||
json.tryGet('sender_claimed_ed25519_key') ?? '',
|
||||
forwardingCurve25519KeyChain =
|
||||
json.tryGetList<String>('forwarding_curve25519_key_chain', []),
|
||||
json.tryGetList('forwarding_curve25519_key_chain') ?? [],
|
||||
super.fromJson(json);
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -43,12 +42,12 @@ class OlmPlaintextPayload {
|
|||
|
||||
factory OlmPlaintextPayload.fromJson(Map<String, dynamic> json) =>
|
||||
OlmPlaintextPayload(
|
||||
sender: json.tryGet<String>('sender'),
|
||||
type: json.tryGet<String>('type'),
|
||||
content: json.tryGetMap<String, dynamic>('content'),
|
||||
recipient: json.tryGet<String>('recipient'),
|
||||
recipientKeys: json.tryGetMap<String, String>('recipient_keys'),
|
||||
keys: json.tryGetMap<String, String>('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<String, dynamic> toJson() {
|
||||
|
|
|
|||
|
|
@ -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<String, CiphertextInfo>? ciphertextOlm;
|
||||
|
||||
RoomEncryptedContent.fromJson(Map<String, dynamic> json)
|
||||
: algorithm = json.tryGet<String>('algorithm', ''),
|
||||
senderKey = json.tryGet<String>('sender_key', ''),
|
||||
deviceId = json.tryGet<String>('device_id'),
|
||||
sessionId = json.tryGet<String>('session_id'),
|
||||
ciphertextMegolm = json['ciphertext'] is String
|
||||
? json.tryGet<String>('ciphertext')
|
||||
: null,
|
||||
ciphertextOlm = json['ciphertext'] is Map<String, dynamic>
|
||||
? json
|
||||
.tryGet<Map<String, dynamic>>('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<Map<String, dynamic>>('ciphertext')
|
||||
?.map((k, v) => MapEntry(k, CiphertextInfo.fromJson(v)));
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
@ -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<String, dynamic> json)
|
||||
: body = json.tryGet<String>('body'),
|
||||
type = json.tryGet<int>('type');
|
||||
: body = json['body'],
|
||||
type = json['type'];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (body != null) {
|
||||
data['body'] = body;
|
||||
}
|
||||
if (type != null) {
|
||||
data['type'] = type;
|
||||
}
|
||||
data['body'] = body;
|
||||
data['type'] = type;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
: algorithm = json.tryGet<String>('algorithm', ''),
|
||||
rotationPeriodMs = json.tryGet<int?>('rotation_period_ms'),
|
||||
rotationPeriodMsgs = json.tryGet<int?>('rotation_period_msgs');
|
||||
: algorithm = json.tryGet('algorithm') ?? '',
|
||||
rotationPeriodMs = json.tryGet('rotation_period_ms'),
|
||||
rotationPeriodMsgs = json.tryGet('rotation_period_msgs');
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
: algorithm = json.tryGet<String>('algorithm', ''),
|
||||
roomId = json.tryGet<String>('room_id', ''),
|
||||
sessionId = json.tryGet<String>('session_id', ''),
|
||||
sessionKey = json.tryGet<String>('session_key', '');
|
||||
: algorithm = json.tryGet('algorithm') ?? '',
|
||||
roomId = json.tryGet('room_id') ?? '',
|
||||
sessionId = json.tryGet('session_id') ?? '',
|
||||
sessionKey = json.tryGet('session_key') ?? '';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
: body = RequestedKeyInfo.fromJson(
|
||||
: body = ((x) => x != null ? RequestedKeyInfo.fromJson(x) : null)(
|
||||
json.tryGet<Map<String, dynamic>>('body')),
|
||||
action = json.tryGet<String>('action', ''),
|
||||
requestingDeviceId = json.tryGet<String>('requesting_device_id', ''),
|
||||
requestId = json.tryGet<String>('request_id', '');
|
||||
action = json.tryGet<String>('action') ?? '',
|
||||
requestingDeviceId = json.tryGet<String>('requesting_device_id') ?? '',
|
||||
requestId = json.tryGet<String>('request_id') ?? '';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
@ -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<String, dynamic> json) {
|
||||
if (json == null) return null;
|
||||
final requestKeyInfo = RequestedKeyInfo();
|
||||
requestKeyInfo.algorithm = json.tryGet<String>('algorithm', '');
|
||||
requestKeyInfo.roomId = json.tryGet<String>('room_id', '');
|
||||
requestKeyInfo.sessionId = json.tryGet<String>('session_id', '');
|
||||
requestKeyInfo.senderKey = json.tryGet<String>('sender_key', '');
|
||||
return requestKeyInfo;
|
||||
}
|
||||
RequestedKeyInfo.fromJson(Map<String, dynamic> json)
|
||||
: algorithm = json.tryGet('algorithm') ?? '',
|
||||
roomId = json.tryGet('room_id') ?? '',
|
||||
sessionId = json.tryGet('session_id') ?? '',
|
||||
senderKey = json.tryGet('sender_key') ?? '';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
: key = json.tryGet<String>('key');
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic>
|
||||
? PassphraseInfo.fromJson(json['passphrase'])
|
||||
: null,
|
||||
iv = json.tryGet<String?>('iv'),
|
||||
mac = json.tryGet<String?>('mac'),
|
||||
algorithm = json.tryGet<String?>('algorithm');
|
||||
iv = json.tryGet('iv'),
|
||||
mac = json.tryGet('mac'),
|
||||
algorithm = json.tryGet('algorithm');
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
@ -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<String, dynamic> json)
|
||||
: algorithm = json.tryGet<String>('algorithm'),
|
||||
salt = json.tryGet<String>('salt'),
|
||||
iterations = json.tryGet<int>('iterations'),
|
||||
: algorithm = json.tryGet('algorithm'),
|
||||
salt = json.tryGet('salt'),
|
||||
iterations = json.tryGet('iterations'),
|
||||
bits = json.tryGet<int>('bits');
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json)
|
||||
: body = json.tryGet<String>('body', ''),
|
||||
replacementRoom = json.tryGet<String>('replacement_room', '');
|
||||
: body = json.tryGet('body') ?? '',
|
||||
replacementRoom = json.tryGet('replacement_room') ?? '';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic>? unsigned;
|
||||
Map<String, dynamic>? prevContent;
|
||||
String? redacts;
|
||||
|
||||
MatrixEvent();
|
||||
MatrixEvent({
|
||||
required String type,
|
||||
required Map<String, dynamic> 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<String, dynamic> json)
|
||||
: eventId = json['event_id'],
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> 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<AuthenticationFlow>?/*?*/ get authenticationFlows {
|
||||
List<AuthenticationFlow>? 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<String> stages;
|
||||
|
||||
const AuthenticationFlow(this.stages);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, String> keys;
|
||||
Map<String, Map<String, String>>? signatures;
|
||||
Map<String, dynamic>? 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<String, dynamic>? _json;
|
||||
|
|
@ -65,6 +65,7 @@ class MatrixSignableKey {
|
|||
|
||||
class MatrixCrossSigningKey extends MatrixSignableKey {
|
||||
List<String> usage;
|
||||
|
||||
String? get publicKey => identifier;
|
||||
|
||||
MatrixCrossSigningKey(
|
||||
|
|
@ -73,14 +74,15 @@ class MatrixCrossSigningKey extends MatrixSignableKey {
|
|||
Map<String, String> keys,
|
||||
Map<String, Map<String, String>> signatures, {
|
||||
Map<String, dynamic>? 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<String, dynamic> json)
|
||||
: super.fromJson(json) {
|
||||
usage = List<String>.from(json['usage']);
|
||||
identifier = keys?.values?.first;
|
||||
}
|
||||
: usage = List<String>.from(json['usage']),
|
||||
super.fromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -91,25 +93,29 @@ class MatrixCrossSigningKey extends MatrixSignableKey {
|
|||
}
|
||||
|
||||
class MatrixDeviceKeys extends MatrixSignableKey {
|
||||
String get deviceId => identifier!;
|
||||
String deviceId;
|
||||
List<String> algorithms;
|
||||
|
||||
String? get deviceDisplayName =>
|
||||
unsigned != null ? unsigned!['device_display_name'] : null;
|
||||
|
||||
MatrixDeviceKeys(
|
||||
String userId,
|
||||
String deviceId,
|
||||
this.deviceId,
|
||||
this.algorithms,
|
||||
Map<String, String> keys,
|
||||
Map<String, Map<String, String>> signatures, {
|
||||
Map<String, dynamic>? unsigned,
|
||||
}) : super(userId, deviceId, keys, signatures, unsigned: unsigned);
|
||||
}) : super(userId, keys, signatures, unsigned: unsigned);
|
||||
|
||||
@override
|
||||
MatrixDeviceKeys.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
identifier = json['device_id'];
|
||||
algorithms = json['algorithms'].cast<String>();
|
||||
}
|
||||
String? get identifier => deviceId;
|
||||
|
||||
@override
|
||||
MatrixDeviceKeys.fromJson(Map<String, dynamic> json)
|
||||
: algorithms = json['algorithms'].cast<String>(),
|
||||
deviceId = json['device_id'],
|
||||
super.fromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
abstract class RoomCreationTypes {
|
||||
static const String mSpace = 'm.space';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -53,9 +52,7 @@ class RoomKeysSingleKey {
|
|||
class RoomKeysRoom {
|
||||
Map<String, RoomKeysSingleKey> sessions;
|
||||
|
||||
RoomKeysRoom({required this.sessions}) {
|
||||
sessions ??= <String, RoomKeysSingleKey>{};
|
||||
}
|
||||
RoomKeysRoom({required this.sessions});
|
||||
|
||||
RoomKeysRoom.fromJson(Map<String, dynamic> json)
|
||||
: sessions = (json['sessions'] as Map)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -26,6 +25,7 @@ class RoomSummary {
|
|||
List<String>? mHeroes;
|
||||
int? mJoinedMemberCount;
|
||||
int? mInvitedMemberCount;
|
||||
|
||||
RoomSummary.fromJson(Map<String, dynamic> json)
|
||||
: mHeroes = json['m.heroes'] != null
|
||||
? List<String>.from(json['m.heroes'])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> content,
|
||||
required String senderId,
|
||||
this.stateKey})
|
||||
: super(type: type, content: content, senderId: senderId);
|
||||
|
||||
StrippedStateEvent.fromJson(Map<String, dynamic> json)
|
||||
: stateKey = json['state_key'],
|
||||
super.fromJson(json);
|
||||
|
|
|
|||
|
|
@ -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<String, dynamic> json) {
|
||||
regexp = json['regexp'];
|
||||
placeholder = json['placeholder'];
|
||||
}
|
||||
ProtocolFieldType.fromJson(Map<String, dynamic> json)
|
||||
: regexp = json['regexp'],
|
||||
placeholder = json['placeholder'];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
@ -75,12 +71,11 @@ class ProtocolInstance {
|
|||
String? icon;
|
||||
dynamic fields;
|
||||
|
||||
ProtocolInstance.fromJson(Map<String, dynamic> json) {
|
||||
networkId = json['network_id'];
|
||||
desc = json['desc'];
|
||||
icon = json['icon'];
|
||||
fields = json['fields'];
|
||||
}
|
||||
ProtocolInstance.fromJson(Map<String, dynamic> json)
|
||||
: networkId = json['network_id'],
|
||||
desc = json['desc'],
|
||||
icon = json['icon'],
|
||||
fields = json['fields'];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -40,7 +39,7 @@ class SyncUpdate {
|
|||
Map<String, int>? deviceOneTimeKeysCount;
|
||||
List<String>? deviceUnusedFallbackKeyTypes;
|
||||
|
||||
SyncUpdate();
|
||||
SyncUpdate({required this.nextBatch});
|
||||
|
||||
SyncUpdate.fromJson(Map<String, dynamic> json)
|
||||
: nextBatch = json['next_batch'],
|
||||
|
|
@ -136,6 +135,7 @@ class RoomsUpdate {
|
|||
.map((k, v) => MapEntry(k, LeftRoomUpdate.fromJson(v)))
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (join != null) {
|
||||
|
|
@ -224,6 +224,7 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
|
|||
|
||||
class InvitedRoomUpdate extends SyncRoomUpdate {
|
||||
List<StrippedStateEvent>? inviteState;
|
||||
|
||||
InvitedRoomUpdate.fromJson(Map<String, dynamic> json) {
|
||||
inviteState =
|
||||
(json['invite_state'] != null && json['invite_state']['events'] != null)
|
||||
|
|
@ -232,6 +233,7 @@ class InvitedRoomUpdate extends SyncRoomUpdate {
|
|||
.toList()
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (inviteState != null) {
|
||||
|
|
@ -266,6 +268,7 @@ class LeftRoomUpdate extends SyncRoomUpdate {
|
|||
.toList()
|
||||
: null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (state != null) {
|
||||
|
|
@ -318,10 +321,12 @@ class TimelineUpdate {
|
|||
class UnreadNotificationCounts {
|
||||
int? highlightCount;
|
||||
int? notificationCount;
|
||||
|
||||
UnreadNotificationCounts.fromJson(Map<String, dynamic> json) {
|
||||
highlightCount = json['highlight_count'];
|
||||
notificationCount = json['notification_count'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (highlightCount != null) {
|
||||
|
|
@ -337,10 +342,12 @@ class UnreadNotificationCounts {
|
|||
class DeviceListsUpdate {
|
||||
List<String>? changed;
|
||||
List<String>? left;
|
||||
|
||||
DeviceListsUpdate.fromJson(Map<String, dynamic> json) {
|
||||
changed = List<String>.from(json['changed'] ?? []);
|
||||
left = List<String>.from(json['left'] ?? []);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
if (changed != null) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -25,60 +24,45 @@
|
|||
import 'logs.dart';
|
||||
|
||||
extension TryGetMapExtension on Map<String, dynamic> {
|
||||
T tryGet<T>(String key, [T fallbackValue]) {
|
||||
T? tryGet<T extends Object>(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<T> tryGetList<T>(String key, [List<T> fallbackValue]) {
|
||||
List<T>? tryGetList<T>(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<T>();
|
||||
} catch (_) {
|
||||
Logs().w(
|
||||
'Unable to create "List<${T.runtimeType}>" in event content for the key "$key"');
|
||||
return fallbackValue;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<A, B> tryGetMap<A, B>(String key, [Map<A, B> fallbackValue]) {
|
||||
Map<A, B>? tryGetMap<A, B>(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<A, B>();
|
||||
} catch (_) {
|
||||
Logs().w(
|
||||
'Unable to create "Map<${A.runtimeType},${B.runtimeType}>" in event content for the key "$key"');
|
||||
return fallbackValue;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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', () {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
|
|
@ -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<List<LoginFlow>>);
|
||||
expect(loginTypes.first.type, 'm.login.password');
|
||||
final loginTypes = await matrixApi.getLoginFlows();
|
||||
expect(loginTypes?.first.type, 'm.login.password');
|
||||
expect(FakeMatrixApi.api['GET'],
|
||||
{'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'],
|
||||
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'],
|
||||
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<List<ThirdPartyIdentifier>>);
|
||||
final response = await matrixApi.getAccount3PIDs();
|
||||
expect(FakeMatrixApi.api['GET'],
|
||||
{'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<List<MatrixEvent>>);
|
||||
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<Map<String, RoomMember>>);
|
||||
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'],
|
||||
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'],
|
||||
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'],
|
||||
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'],
|
||||
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<List<Device>>);
|
||||
final devices = await matrixApi.getDevices();
|
||||
expect(FakeMatrixApi.api['GET']['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'],
|
||||
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<List<Pusher>>);
|
||||
final response = await matrixApi.getPushers();
|
||||
expect(
|
||||
FakeMatrixApi.api['GET'],
|
||||
{'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'],
|
||||
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'],
|
||||
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'],
|
||||
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<Map<String, Tag>>);
|
||||
final response = await matrixApi.getRoomTags(
|
||||
'@alice:example.com', '!localpart:example.com');
|
||||
expect(
|
||||
FakeMatrixApi.api['GET'],
|
||||
{'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'],
|
||||
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'],
|
||||
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'],
|
||||
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'],
|
||||
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']['version'],
|
||||
ret);
|
||||
});
|
||||
test('getRoomKeysVersionCurrent', () async {
|
||||
|
|
@ -1656,7 +1654,8 @@ void main() {
|
|||
matrixApi.accessToken = '1234';
|
||||
|
||||
final ret = await matrixApi.getRoomKeysVersionCurrent();
|
||||
expect(FakeMatrixApi.api['GET'],
|
||||
expect(
|
||||
FakeMatrixApi.api['GET'],
|
||||
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'],
|
||||
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'],
|
||||
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'],
|
||||
ret.toJson());
|
||||
});
|
||||
test('AuthenticationData', () {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
|
|||
Loading…
Reference in New Issue