diff --git a/lib/src/model/auth/authentication_three_pid_creds.dart b/lib/src/model/auth/authentication_three_pid_creds.dart index 292646a4..b6278160 100644 --- a/lib/src/model/auth/authentication_three_pid_creds.dart +++ b/lib/src/model/auth/authentication_three_pid_creds.dart @@ -28,7 +28,7 @@ import 'authentication_data.dart'; /// Or phone number based identity: /// https://matrix.org/docs/spec/client_server/r0.6.1#phone-number-msisdn-based-identity-homeserver class AuthenticationThreePidCreds extends AuthenticationData { - late List threepidCreds; + late ThreepidCreds threepidCreds; AuthenticationThreePidCreds( {String? session, required String type, required this.threepidCreds}) @@ -39,27 +39,16 @@ class AuthenticationThreePidCreds extends AuthenticationData { AuthenticationThreePidCreds.fromJson(Map json) : super.fromJson(json) { - if (json['threepidCreds'] != null) { - threepidCreds = (json['threepidCreds'] as List) - .map((item) => ThreepidCreds.fromJson(item)) - .toList(); - } - - // This is so extremly stupid... kill it with fire! - if (json['threepid_creds'] != null) { - threepidCreds = (json['threepid_creds'] as List) - .map((item) => ThreepidCreds.fromJson(item)) - .toList(); + final creds = json['threepid_creds']; + if (creds is Map) { + threepidCreds = ThreepidCreds.fromJson(creds); } } @override Map toJson() { final data = super.toJson(); - data['threepidCreds'] = threepidCreds.map((t) => t.toJson()).toList(); - // Help me! I'm prisoned in a developer factory against my will, - // where we are forced to work with json like this!! - data['threepid_creds'] = threepidCreds.map((t) => t.toJson()).toList(); + data['threepid_creds'] = threepidCreds.toJson(); return data; } } diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index f615e5c5..af414dea 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -1807,37 +1807,26 @@ void main() { test('AuthenticationThreePidCreds', () { final json = { 'type': 'm.login.email.identity', - 'threepidCreds': [ - { - 'sid': '1', - 'client_secret': 'a', - 'id_server': 'matrix.org', - 'id_access_token': 'a', - }, - ], - 'threepid_creds': [ - { - 'sid': '1', - 'client_secret': 'a', - 'id_server': 'matrix.org', - 'id_access_token': 'a', - }, - ], + 'threepid_creds': { + 'sid': '1', + 'client_secret': 'a', + 'id_server': 'matrix.org', + 'id_access_token': 'a', + }, 'session': '1', }; expect(AuthenticationThreePidCreds.fromJson(json).toJson(), json); expect( AuthenticationThreePidCreds( - session: '1', - type: AuthenticationTypes.emailIdentity, - threepidCreds: [ - ThreepidCreds( - sid: '1', - clientSecret: 'a', - idServer: 'matrix.org', - idAccessToken: 'a', - ), - ]).toJson(), + session: '1', + type: AuthenticationTypes.emailIdentity, + threepidCreds: ThreepidCreds( + sid: '1', + clientSecret: 'a', + idServer: 'matrix.org', + idAccessToken: 'a', + ), + ).toJson(), json); }); test('AuthenticationIdentifier', () {