fix: Typo and wellknown parsing
This commit is contained in:
parent
512abfc476
commit
7d91cdac5e
|
|
@ -19,7 +19,7 @@ code_analyze:
|
|||
image: cirrusci/flutter
|
||||
dependencies: []
|
||||
script:
|
||||
- flutter format lib/ test/ test_driver/ --set-exit-if-changed
|
||||
- flutter format lib/ test/ --set-exit-if-changed
|
||||
- flutter analyze
|
||||
|
||||
build_api_doc:
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ flutter format lib/**/*/*.dart
|
|||
- Don't repeat yourself! Use local variables, functions, classes.
|
||||
- Write tests for new classes, functions and widgets.
|
||||
- Keep it simple stupid: https://en.wikipedia.org/wiki/KISS_principle
|
||||
- Describe all of your classes, methods and attributes using **dartdoc** comments. Read this for more informations: https://dart.dev/guides/language/effective-dart/documentation
|
||||
- Describe all of your classes, methods and attributes using **dartdoc** comments. Read this for more information: https://dart.dev/guides/language/effective-dart/documentation
|
||||
|
|
@ -55,7 +55,7 @@ export 'src/model/public_rooms_response.dart';
|
|||
export 'src/model/push_rule_set.dart';
|
||||
export 'src/model/pusher.dart';
|
||||
export 'src/model/request_token_response.dart';
|
||||
export 'src/model/room_alias_informations.dart';
|
||||
export 'src/model/room_alias_information.dart';
|
||||
export 'src/model/room_keys_info.dart';
|
||||
export 'src/model/room_keys_keys.dart';
|
||||
export 'src/model/room_summary.dart';
|
||||
|
|
@ -72,7 +72,7 @@ export 'src/model/timeline_history_response.dart';
|
|||
export 'src/model/turn_server_credentials.dart';
|
||||
export 'src/model/upload_key_signatures_response.dart';
|
||||
export 'src/model/user_search_result.dart';
|
||||
export 'src/model/well_known_informations.dart';
|
||||
export 'src/model/well_known_information.dart';
|
||||
export 'src/model/who_is_info.dart';
|
||||
export 'src/model/auth/authentication_data.dart';
|
||||
export 'src/model/auth/authentication_identifier.dart';
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import 'model/public_rooms_response.dart';
|
|||
import 'model/push_rule_set.dart';
|
||||
import 'model/pusher.dart';
|
||||
import 'model/request_token_response.dart';
|
||||
import 'model/room_alias_informations.dart';
|
||||
import 'model/room_alias_information.dart';
|
||||
import 'model/room_keys_info.dart';
|
||||
import 'model/room_keys_keys.dart';
|
||||
import 'model/server_capabilities.dart';
|
||||
|
|
@ -66,7 +66,7 @@ import 'model/timeline_history_response.dart';
|
|||
import 'model/turn_server_credentials.dart';
|
||||
import 'model/upload_key_signatures_response.dart';
|
||||
import 'model/user_search_result.dart';
|
||||
import 'model/well_known_informations.dart';
|
||||
import 'model/well_known_information.dart';
|
||||
import 'model/who_is_info.dart';
|
||||
|
||||
enum RequestType { GET, POST, PUT, DELETE }
|
||||
|
|
@ -233,14 +233,14 @@ class MatrixApi {
|
|||
|
||||
/// Gets discovery information about the domain. The file may include additional keys.
|
||||
/// https://matrix.org/docs/spec/client_server/r0.6.0#get-well-known-matrix-client
|
||||
Future<WellKnownInformations> requestWellKnownInformations() async {
|
||||
Future<WellKnownInformation> requestWellKnownInformation() async {
|
||||
var baseUrl = homeserver.toString();
|
||||
if (baseUrl.endsWith('/')) {
|
||||
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
|
||||
}
|
||||
final response = await httpClient.get('$baseUrl/.well-known/matrix/client');
|
||||
final rawJson = json.decode(response.body);
|
||||
return WellKnownInformations.fromJson(rawJson);
|
||||
return WellKnownInformation.fromJson(rawJson);
|
||||
}
|
||||
|
||||
Future<LoginTypes> requestLoginTypes() async {
|
||||
|
|
@ -883,13 +883,12 @@ class MatrixApi {
|
|||
|
||||
/// Requests that the server resolve a room alias to a room ID.
|
||||
/// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-directory-room-roomalias
|
||||
Future<RoomAliasInformations> requestRoomAliasInformations(
|
||||
String alias) async {
|
||||
Future<RoomAliasInformation> requestRoomAliasInformation(String alias) async {
|
||||
final response = await request(
|
||||
RequestType.GET,
|
||||
'/client/r0/directory/room/${Uri.encodeComponent(alias)}',
|
||||
);
|
||||
return RoomAliasInformations.fromJson(response);
|
||||
return RoomAliasInformation.fromJson(response);
|
||||
}
|
||||
|
||||
/// Remove a mapping of room alias to room ID.
|
||||
|
|
@ -1726,7 +1725,7 @@ class MatrixApi {
|
|||
/// Performs a full text search across different categories.
|
||||
/// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-search
|
||||
/// Please note: The specification is not 100% clear what it is expecting and sending here.
|
||||
/// So we stick with pure json until we have more informations.
|
||||
/// So we stick with pure json until we have more information.
|
||||
Future<Map<String, dynamic>> globalSearch(Map<String, dynamic> query) async {
|
||||
return await request(
|
||||
RequestType.POST,
|
||||
|
|
|
|||
|
|
@ -21,21 +21,20 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import 'well_known_informations.dart';
|
||||
import 'well_known_information.dart';
|
||||
|
||||
class LoginResponse {
|
||||
String userId;
|
||||
String accessToken;
|
||||
String deviceId;
|
||||
WellKnownInformations wellKnownInformations;
|
||||
WellKnownInformation wellKnownInformation;
|
||||
|
||||
LoginResponse.fromJson(Map<String, dynamic> json) {
|
||||
userId = json['user_id'];
|
||||
accessToken = json['access_token'];
|
||||
deviceId = json['device_id'];
|
||||
if (json['well_known'] is Map) {
|
||||
wellKnownInformations =
|
||||
WellKnownInformations.fromJson(json['well_known']);
|
||||
wellKnownInformation = WellKnownInformation.fromJson(json['well_known']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,8 +43,8 @@ class LoginResponse {
|
|||
if (userId != null) data['user_id'] = userId;
|
||||
if (accessToken != null) data['access_token'] = accessToken;
|
||||
if (deviceId != null) data['device_id'] = deviceId;
|
||||
if (wellKnownInformations != null) {
|
||||
data['well_known'] = wellKnownInformations.toJson();
|
||||
if (wellKnownInformation != null) {
|
||||
data['well_known'] = wellKnownInformation.toJson();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
class RoomAliasInformations {
|
||||
class RoomAliasInformation {
|
||||
String roomId;
|
||||
List<String> servers;
|
||||
|
||||
RoomAliasInformations.fromJson(Map<String, dynamic> json) {
|
||||
RoomAliasInformation.fromJson(Map<String, dynamic> json) {
|
||||
roomId = json['room_id'];
|
||||
servers = json['servers'].cast<String>();
|
||||
}
|
||||
|
|
@ -21,25 +21,34 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
class WellKnownInformations {
|
||||
import '../utils/try_get_map_extension.dart';
|
||||
|
||||
class WellKnownInformation {
|
||||
MHomeserver mHomeserver;
|
||||
MHomeserver mIdentityServer;
|
||||
Map<String, dynamic> content;
|
||||
|
||||
WellKnownInformations.fromJson(Map<String, dynamic> json) {
|
||||
WellKnownInformation.fromJson(Map<String, dynamic> json) {
|
||||
content = json;
|
||||
mHomeserver = json['m.homeserver'] != null
|
||||
? MHomeserver.fromJson(json['m.homeserver'])
|
||||
: null;
|
||||
mIdentityServer = json['m.identity_server'] != null
|
||||
? MHomeserver.fromJson(json['m.identity_server'])
|
||||
: null;
|
||||
final mHomeserverMap = json.tryGetMap<String, dynamic>('m.homeserver');
|
||||
if (mHomeserverMap != null) {
|
||||
mHomeserver = MHomeserver.fromJson(mHomeserverMap);
|
||||
}
|
||||
final mIdentityServerMap =
|
||||
json.tryGetMap<String, dynamic>('m.identity_server');
|
||||
if (mIdentityServerMap != null) {
|
||||
mIdentityServer = MHomeserver.fromJson(mIdentityServerMap);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = content;
|
||||
data['m.homeserver'] = mHomeserver.toJson();
|
||||
data['m.identity_server'] = mIdentityServer.toJson();
|
||||
if (mHomeserver != null) {
|
||||
data['m.homeserver'] = mHomeserver.toJson();
|
||||
}
|
||||
if (mIdentityServer != null) {
|
||||
data['m.identity_server'] = mIdentityServer.toJson();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,12 +57,12 @@ class MHomeserver {
|
|||
String baseUrl;
|
||||
|
||||
MHomeserver.fromJson(Map<String, dynamic> json) {
|
||||
baseUrl = json['base_url'];
|
||||
baseUrl = json.tryGet<String>('base_url');
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
data['base_url'] = baseUrl;
|
||||
if (baseUrl != null) data['base_url'] = baseUrl;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -129,13 +129,13 @@ void main() {
|
|||
supportedVersions.toJson());
|
||||
matrixApi.homeserver = null;
|
||||
});
|
||||
test('getWellKnownInformations', () async {
|
||||
test('getWellKnownInformation', () async {
|
||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||
final wellKnownInformations =
|
||||
await matrixApi.requestWellKnownInformations();
|
||||
expect(wellKnownInformations.mHomeserver.baseUrl,
|
||||
final wellKnownInformation =
|
||||
await matrixApi.requestWellKnownInformation();
|
||||
expect(wellKnownInformation.mHomeserver.baseUrl,
|
||||
'https://fakeserver.notexisting');
|
||||
expect(wellKnownInformations.toJson(), {
|
||||
expect(wellKnownInformation.toJson(), {
|
||||
'm.homeserver': {'base_url': 'https://fakeserver.notexisting'},
|
||||
'm.identity_server': {
|
||||
'base_url': 'https://identity.fakeserver.notexisting'
|
||||
|
|
@ -654,19 +654,18 @@ void main() {
|
|||
|
||||
matrixApi.homeserver = matrixApi.accessToken = null;
|
||||
});
|
||||
test('requestRoomAliasInformations', () async {
|
||||
test('requestRoomAliasInformation', () async {
|
||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||
matrixApi.accessToken = '1234';
|
||||
|
||||
final roomAliasInformations =
|
||||
await matrixApi.requestRoomAliasInformations(
|
||||
final roomAliasInformation = await matrixApi.requestRoomAliasInformation(
|
||||
'#testalias:example.com',
|
||||
);
|
||||
|
||||
expect(
|
||||
FakeMatrixApi.api['GET']
|
||||
['/client/r0/directory/room/%23testalias%3Aexample.com']({}),
|
||||
roomAliasInformations.toJson());
|
||||
roomAliasInformation.toJson());
|
||||
|
||||
matrixApi.homeserver = matrixApi.accessToken = null;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue