diff --git a/lib/matrix_api/matrix_api.dart b/lib/matrix_api/matrix_api.dart index 6f87e88..770dd25 100644 --- a/lib/matrix_api/matrix_api.dart +++ b/lib/matrix_api/matrix_api.dart @@ -18,13 +18,14 @@ import 'dart:async'; import 'dart:convert'; + import 'package:famedlysdk/matrix_api/model/filter.dart'; import 'package:famedlysdk/matrix_api/model/keys_query_response.dart'; import 'package:famedlysdk/matrix_api/model/login_types.dart'; import 'package:famedlysdk/matrix_api/model/notifications_query_response.dart'; import 'package:famedlysdk/matrix_api/model/open_graph_data.dart'; -import 'package:famedlysdk/matrix_api/model/request_token_response.dart'; import 'package:famedlysdk/matrix_api/model/profile.dart'; +import 'package:famedlysdk/matrix_api/model/request_token_response.dart'; import 'package:famedlysdk/matrix_api/model/server_capabilities.dart'; import 'package:famedlysdk/matrix_api/model/supported_versions.dart'; import 'package:famedlysdk/matrix_api/model/sync_update.dart'; @@ -36,12 +37,12 @@ import 'package:mime/mime.dart'; import 'package:moor/moor.dart'; import 'model/device.dart'; -import 'model/matrix_event.dart'; -import 'model/matrix_keys.dart'; import 'model/event_context.dart'; import 'model/events_sync_update.dart'; import 'model/login_response.dart'; +import 'model/matrix_event.dart'; import 'model/matrix_exception.dart'; +import 'model/matrix_keys.dart'; import 'model/one_time_keys_claim_response.dart'; import 'model/open_id_credentials.dart'; import 'model/presence_content.dart'; @@ -192,7 +193,13 @@ class MatrixApi { ); break; } - var jsonString = String.fromCharCodes(resp.body.runes); + var respBody = resp.body; + try { + respBody = utf8.decode(resp.bodyBytes); + } catch (_) { + // No-OP + } + var jsonString = String.fromCharCodes(respBody.runes); if (jsonString.startsWith('[') && jsonString.endsWith(']')) { jsonString = '\{"chunk":$jsonString\}'; } diff --git a/lib/src/client.dart b/lib/src/client.dart index 8815688..bdd2ada 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -20,9 +20,9 @@ import 'dart:async'; import 'dart:convert'; import 'dart:core'; +import 'package:famedlysdk/encryption.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/matrix_api.dart'; -import 'package:famedlysdk/encryption.dart'; import 'package:famedlysdk/src/room.dart'; import 'package:famedlysdk/src/utils/device_keys_list.dart'; import 'package:famedlysdk/src/utils/matrix_file.dart'; @@ -30,12 +30,12 @@ import 'package:famedlysdk/src/utils/to_device_event.dart'; import 'package:http/http.dart' as http; import 'package:pedantic/pedantic.dart'; +import 'database/database.dart' show Database; import 'event.dart'; import 'room.dart'; +import 'user.dart'; import 'utils/event_update.dart'; import 'utils/room_update.dart'; -import 'user.dart'; -import 'database/database.dart' show Database; typedef RoomSorter = int Function(Room a, Room b); @@ -231,7 +231,13 @@ class Client { ) async { final response = await http .get('https://${MatrixIdOrDomain.domain}/.well-known/matrix/client'); - final rawJson = json.decode(response.body); + var respBody = response.body; + try { + respBody = utf8.decode(response.bodyBytes); + } catch (_) { + // No-OP + } + final rawJson = json.decode(respBody); return WellKnownInformations.fromJson(rawJson); }