diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index d078d32c..a56b543a 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -22,9 +22,7 @@ import 'dart:async'; import 'package:pedantic/pedantic.dart'; import '../famedlysdk.dart'; -import '../matrix_api.dart'; import '../src/utils/run_in_root.dart'; -import '../matrix_api/utils/logs.dart'; import 'cross_signing.dart'; import 'key_manager.dart'; import 'key_verification_manager.dart'; diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index d0519554..0c5c95a3 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -24,13 +24,9 @@ import './encryption.dart'; import './utils/outbound_group_session.dart'; import './utils/session_key.dart'; import '../famedlysdk.dart'; -import '../matrix_api.dart'; import '../src/database/database.dart'; -import '../matrix_api/utils/logs.dart'; import '../src/utils/run_in_background.dart'; import '../src/utils/run_in_root.dart'; -import '../matrix_api/utils/try_get_map_extension.dart'; -import '../matrix_api/utils/map_copy_extension.dart'; const MEGOLM_KEY = EventTypes.MegolmBackup; diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index fc678728..ada3ce36 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -20,12 +20,10 @@ import 'dart:convert'; import 'package:canonical_json/canonical_json.dart'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:olm/olm.dart' as olm; import 'package:pedantic/pedantic.dart'; import '../encryption/utils/json_signature_check_extension.dart'; -import '../matrix_api/utils/logs.dart'; import 'encryption.dart'; import 'utils/olm_session.dart'; import '../src/utils/run_in_root.dart'; diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 4c4191f9..200965d7 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -27,9 +27,7 @@ import 'package:encrypt/encrypt.dart'; import 'package:password_hash/password_hash.dart'; import '../famedlysdk.dart'; -import '../matrix_api.dart'; import '../src/database/database.dart'; -import '../matrix_api/utils/logs.dart'; import '../src/utils/run_in_background.dart'; import 'encryption.dart'; diff --git a/lib/encryption/utils/bootstrap.dart b/lib/encryption/utils/bootstrap.dart index 72fecc97..dc525fc7 100644 --- a/lib/encryption/utils/bootstrap.dart +++ b/lib/encryption/utils/bootstrap.dart @@ -26,7 +26,6 @@ import '../encryption.dart'; import '../ssss.dart'; import '../key_manager.dart'; import '../../famedlysdk.dart'; -import '../../matrix_api/utils/logs.dart'; enum BootstrapState { /// Is loading. diff --git a/lib/encryption/utils/json_signature_check_extension.dart b/lib/encryption/utils/json_signature_check_extension.dart index 920ca393..dc2501a5 100644 --- a/lib/encryption/utils/json_signature_check_extension.dart +++ b/lib/encryption/utils/json_signature_check_extension.dart @@ -1,7 +1,8 @@ import 'package:canonical_json/canonical_json.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:olm/olm.dart' as olm; +import '../../famedlysdk.dart'; + extension JsonSignatureCheckExtension on Map { /// Checks the signature of a signed json object. bool checkJsonSignature(String key, String userId, String deviceId) { diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index cc6f9872..fb6b3626 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -24,8 +24,6 @@ import 'package:olm/olm.dart' as olm; import 'package:pedantic/pedantic.dart'; import '../../famedlysdk.dart'; -import '../../matrix_api.dart'; -import '../../matrix_api/utils/logs.dart'; import '../encryption.dart'; /* diff --git a/lib/encryption/utils/olm_session.dart b/lib/encryption/utils/olm_session.dart index fe987269..d95f2c7b 100644 --- a/lib/encryption/utils/olm_session.dart +++ b/lib/encryption/utils/olm_session.dart @@ -18,8 +18,8 @@ import 'package:olm/olm.dart' as olm; +import '../../famedlysdk.dart'; import '../../src/database/database.dart' show DbOlmSessions; -import '../../matrix_api/utils/logs.dart'; class OlmSession { String identityKey; diff --git a/lib/encryption/utils/outbound_group_session.dart b/lib/encryption/utils/outbound_group_session.dart index ac3bdd2c..dcd11e2b 100644 --- a/lib/encryption/utils/outbound_group_session.dart +++ b/lib/encryption/utils/outbound_group_session.dart @@ -20,8 +20,8 @@ import 'dart:convert'; import 'package:olm/olm.dart' as olm; +import '../../famedlysdk.dart'; import '../../src/database/database.dart' show DbOutboundGroupSession; -import '../../matrix_api/utils/logs.dart'; class OutboundGroupSession { /// The devices is a map from user id to device id to if the device is blocked. diff --git a/lib/encryption/utils/session_key.dart b/lib/encryption/utils/session_key.dart index 3d8e4cda..aa1fc4a5 100644 --- a/lib/encryption/utils/session_key.dart +++ b/lib/encryption/utils/session_key.dart @@ -20,7 +20,6 @@ import 'package:olm/olm.dart' as olm; import '../../famedlysdk.dart'; import '../../src/database/database.dart' show DbInboundGroupSession; -import '../../matrix_api/utils/logs.dart'; class SessionKey { /// The raw json content of the key diff --git a/lib/famedlysdk.dart b/lib/famedlysdk.dart index ff17ff48..f0e1243a 100644 --- a/lib/famedlysdk.dart +++ b/lib/famedlysdk.dart @@ -18,7 +18,7 @@ library famedlysdk; -export 'matrix_api.dart'; +export 'package:matrix_api_lite/matrix_api_lite.dart'; export 'src/utils/room_update.dart'; export 'src/utils/event_update.dart'; export 'src/utils/device_keys_list.dart'; diff --git a/lib/matrix_api.dart b/lib/matrix_api.dart deleted file mode 100644 index 2e13945f..00000000 --- a/lib/matrix_api.dart +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -library matrix_api; - -export 'matrix_api/matrix_api.dart'; -export 'matrix_api/utils/logs.dart'; -export 'matrix_api/utils/map_copy_extension.dart'; -export 'matrix_api/utils/try_get_map_extension.dart'; -export 'matrix_api/model/algorithm_types.dart'; -export 'matrix_api/model/basic_event.dart'; -export 'matrix_api/model/basic_event_with_sender.dart'; -export 'matrix_api/model/basic_room_event.dart'; -export 'matrix_api/model/device.dart'; -export 'matrix_api/model/event_context.dart'; -export 'matrix_api/model/event_types.dart'; -export 'matrix_api/model/events_sync_update.dart'; -export 'matrix_api/model/filter.dart'; -export 'matrix_api/model/keys_query_response.dart'; -export 'matrix_api/model/login_response.dart'; -export 'matrix_api/model/login_types.dart'; -export 'matrix_api/model/matrix_connection_exception.dart'; -export 'matrix_api/model/matrix_event.dart'; -export 'matrix_api/model/matrix_exception.dart'; -export 'matrix_api/model/matrix_keys.dart'; -export 'matrix_api/model/message_types.dart'; -export 'matrix_api/model/notifications_query_response.dart'; -export 'matrix_api/model/one_time_keys_claim_response.dart'; -export 'matrix_api/model/open_graph_data.dart'; -export 'matrix_api/model/open_id_credentials.dart'; -export 'matrix_api/model/presence.dart'; -export 'matrix_api/model/presence_content.dart'; -export 'matrix_api/model/profile.dart'; -export 'matrix_api/model/public_rooms_response.dart'; -export 'matrix_api/model/push_rule_set.dart'; -export 'matrix_api/model/pusher.dart'; -export 'matrix_api/model/request_token_response.dart'; -export 'matrix_api/model/room_alias_informations.dart'; -export 'matrix_api/model/room_keys_info.dart'; -export 'matrix_api/model/room_keys_keys.dart'; -export 'matrix_api/model/room_summary.dart'; -export 'matrix_api/model/server_capabilities.dart'; -export 'matrix_api/model/stripped_state_event.dart'; -export 'matrix_api/model/supported_protocol.dart'; -export 'matrix_api/model/supported_versions.dart'; -export 'matrix_api/model/sync_update.dart'; -export 'matrix_api/model/tag.dart'; -export 'matrix_api/model/third_party_identifier.dart'; -export 'matrix_api/model/third_party_location.dart'; -export 'matrix_api/model/third_party_user.dart'; -export 'matrix_api/model/timeline_history_response.dart'; -export 'matrix_api/model/turn_server_credentials.dart'; -export 'matrix_api/model/upload_key_signatures_response.dart'; -export 'matrix_api/model/user_search_result.dart'; -export 'matrix_api/model/well_known_informations.dart'; -export 'matrix_api/model/who_is_info.dart'; -export 'matrix_api/model/auth/authentication_data.dart'; -export 'matrix_api/model/auth/authentication_identifier.dart'; -export 'matrix_api/model/auth/authentication_password.dart'; -export 'matrix_api/model/auth/authentication_phone_identifier.dart'; -export 'matrix_api/model/auth/authentication_recaptcha.dart'; -export 'matrix_api/model/auth/authentication_third_party_identifier.dart'; -export 'matrix_api/model/auth/authentication_three_pid_creds.dart'; -export 'matrix_api/model/auth/authentication_token.dart'; -export 'matrix_api/model/auth/authentication_types.dart'; -export 'matrix_api/model/auth/authentication_user_identifier.dart'; -export 'matrix_api/model/events/secret_storage_default_key_content.dart'; -export 'matrix_api/model/events/secret_storage_key_content.dart'; -export 'matrix_api/model/events/tombstone_content.dart'; diff --git a/lib/matrix_api/matrix_api.dart b/lib/matrix_api/matrix_api.dart deleted file mode 100644 index a92bf1e0..00000000 --- a/lib/matrix_api/matrix_api.dart +++ /dev/null @@ -1,2126 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'dart:async'; -import 'dart:convert'; - -import 'package:famedlysdk/famedlysdk.dart'; -import 'package:http/http.dart' as http; -import 'package:mime/mime.dart'; -import 'package:moor/moor.dart'; - -import 'model/auth/authentication_types.dart'; -import 'model/device.dart'; -import 'model/event_context.dart'; -import 'model/events_sync_update.dart'; -import 'model/filter.dart'; -import 'model/keys_query_response.dart'; -import 'model/login_response.dart'; -import 'model/login_types.dart'; -import 'model/matrix_connection_exception.dart'; -import 'model/matrix_event.dart'; -import 'model/matrix_exception.dart'; -import 'model/matrix_keys.dart'; -import 'model/notifications_query_response.dart'; -import 'model/one_time_keys_claim_response.dart'; -import 'model/open_graph_data.dart'; -import 'model/open_id_credentials.dart'; -import 'model/presence_content.dart'; -import 'model/profile.dart'; -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_keys_info.dart'; -import 'model/room_keys_keys.dart'; -import 'model/server_capabilities.dart'; -import 'model/supported_protocol.dart'; -import 'model/supported_versions.dart'; -import 'model/sync_update.dart'; -import 'model/tag.dart'; -import 'model/third_party_identifier.dart'; -import 'model/third_party_location.dart'; -import 'model/third_party_user.dart'; -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/who_is_info.dart'; - -enum RequestType { GET, POST, PUT, DELETE } -enum IdServerUnbindResult { success, no_success } -enum ThirdPartyIdentifierMedium { email, msisdn } -enum Membership { join, invite, leave, ban } -enum Direction { b, f } -enum Visibility { public, private } -enum CreateRoomPreset { private_chat, public_chat, trusted_private_chat } - -String describeEnum(Object enumEntry) { - final description = enumEntry.toString(); - final indexOfDot = description.indexOf('.'); - assert(indexOfDot != -1 && indexOfDot < description.length - 1); - return description.substring(indexOfDot + 1); -} - -class MatrixApi { - /// The homeserver this client is communicating with. - Uri homeserver; - - /// This is the access token for the matrix client. When it is undefined, then - /// the user needs to sign in first. - String accessToken; - - /// Matrix synchronisation is done with https long polling. This needs a - /// timeout which is usually 30 seconds. - int syncTimeoutSec; - - http.Client httpClient = http.Client(); - - bool get _testMode => - homeserver.toString() == 'https://fakeserver.notexisting'; - - int _timeoutFactor = 1; - - MatrixApi({ - this.homeserver, - this.accessToken, - http.Client httpClient, - this.syncTimeoutSec = 30, - }) { - if (httpClient != null) { - this.httpClient = httpClient; - } - } - - /// Used for all Matrix json requests using the [c2s API](https://matrix.org/docs/spec/client_server/r0.6.0.html). - /// - /// Throws: TimeoutException, FormatException, MatrixException - /// - /// You must first set [this.homeserver] and for some endpoints also - /// [this.accessToken] before you can use this! For example to send a - /// message to a Matrix room with the id '!fjd823j:example.com' you call: - /// ``` - /// final resp = await request( - /// RequestType.PUT, - /// '/r0/rooms/!fjd823j:example.com/send/m.room.message/$txnId', - /// data: { - /// 'msgtype': 'm.text', - /// 'body': 'hello' - /// } - /// ); - /// ``` - /// - Future> request( - RequestType type, - String action, { - dynamic data = '', - int timeout, - String contentType = 'application/json', - Map query, - }) async { - if (homeserver == null) { - throw ('No homeserver specified.'); - } - timeout ??= (_timeoutFactor * syncTimeoutSec) + 5; - dynamic json; - (!(data is String)) ? json = jsonEncode(data) : json = data; - if (data is List || action.startsWith('/media/r0/upload')) json = data; - - final queryPart = query?.entries - ?.where((x) => x.value != null) - ?.map((x) => [x.key, x.value].map(Uri.encodeQueryComponent).join('=')) - ?.join('&'); - final url = ['${homeserver.toString()}/_matrix${action}', queryPart] - .where((x) => x != null && x != '') - .join('?'); - - var headers = {}; - if (type == RequestType.PUT || type == RequestType.POST) { - headers['Content-Type'] = contentType; - } - if (accessToken != null) { - headers['Authorization'] = 'Bearer ${accessToken}'; - } - - http.Response resp; - var jsonResp = {}; - try { - switch (describeEnum(type)) { - case 'GET': - resp = await httpClient.get(url, headers: headers).timeout( - Duration(seconds: timeout), - ); - break; - case 'POST': - resp = - await httpClient.post(url, body: json, headers: headers).timeout( - Duration(seconds: timeout), - ); - break; - case 'PUT': - resp = - await httpClient.put(url, body: json, headers: headers).timeout( - Duration(seconds: timeout), - ); - break; - case 'DELETE': - resp = await httpClient.delete(url, headers: headers).timeout( - Duration(seconds: timeout), - ); - break; - } - var respBody = resp.body; - try { - respBody = utf8.decode(resp.bodyBytes); - } catch (_) { - // No-OP - } - if (resp.statusCode >= 500 && resp.statusCode < 600) { - throw Exception(respBody); - } - var jsonString = String.fromCharCodes(respBody.runes); - if (jsonString.startsWith('[') && jsonString.endsWith(']')) { - jsonString = '\{"chunk":$jsonString\}'; - } - jsonResp = jsonDecode(jsonString) - as Map; // May throw FormatException - - _timeoutFactor = 1; - } on TimeoutException catch (e, s) { - _timeoutFactor *= 2; - throw MatrixConnectionException(e, s); - } catch (e, s) { - throw MatrixConnectionException(e, s); - } - if (resp.statusCode >= 400 && resp.statusCode < 500) { - throw MatrixException(resp); - } - - return jsonResp; - } - - /// Gets the versions of the specification supported by the server. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-versions - Future requestSupportedVersions() async { - final response = await request( - RequestType.GET, - '/client/versions', - ); - return SupportedVersions.fromJson(response); - } - - /// 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 requestWellKnownInformations() 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); - } - - Future requestLoginTypes() async { - final response = await request( - RequestType.GET, - '/client/r0/login', - ); - return LoginTypes.fromJson(response); - } - - /// Authenticates the user, and issues an access token they can use to authorize themself in subsequent requests. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login - Future login({ - String type = AuthenticationTypes.password, - String userIdentifierType, - String user, - String medium, - String address, - String password, - String token, - String deviceId, - String initialDeviceDisplayName, - AuthenticationData auth, - }) async { - final response = await request(RequestType.POST, '/client/r0/login', data: { - 'type': type, - if (userIdentifierType != null) - 'identifier': { - 'type': userIdentifierType, - if (user != null) 'user': user, - }, - if (user != null) 'user': user, - if (medium != null) 'medium': medium, - if (address != null) 'address': address, - if (password != null) 'password': password, - if (token != null) 'token': token, - if (deviceId != null) 'device_id': deviceId, - if (initialDeviceDisplayName != null) - 'initial_device_display_name': initialDeviceDisplayName, - if (auth != null) 'auth': auth.toJson(), - }); - return LoginResponse.fromJson(response); - } - - /// Invalidates an existing access token, so that it can no longer be used for authorization. - /// The device associated with the access token is also deleted. Device keys for the device - /// are deleted alongside the device. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout - Future logout() async { - await request( - RequestType.POST, - '/client/r0/logout', - ); - return; - } - - /// Invalidates all access tokens for a user, so that they can no longer be used - /// for authorization. This includes the access token that made this request. All - /// devices for the user are also deleted. Device keys for the device are - /// deleted alongside the device. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all - Future logoutAll() async { - await request( - RequestType.POST, - '/client/r0/logout/all', - ); - return; - } - - /// Register for an account on this homeserver. - /// - /// There are two kinds of user account: - /// - /// user accounts. These accounts may use the full API described in this - /// specification. - /// guest accounts. These accounts may have limited permissions and may not - /// be supported by all servers. - /// - /// If registration is successful, this endpoint will issue an access token - /// the client can use to authorize itself in subsequent requests. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register - Future register({ - String username, - String password, - String deviceId, - String initialDeviceDisplayName, - bool inhibitLogin, - AuthenticationData auth, - String kind, - }) async { - var action = '/client/r0/register'; - if (kind != null) action += '?kind=${Uri.encodeQueryComponent(kind)}'; - final response = await request(RequestType.POST, action, data: { - if (username != null) 'username': username, - if (password != null) 'password': password, - if (deviceId != null) 'device_id': deviceId, - if (initialDeviceDisplayName != null) - 'initial_device_display_name': initialDeviceDisplayName, - if (inhibitLogin != null) 'inhibit_login': inhibitLogin, - if (auth != null) 'auth': auth.toJson(), - }); - return LoginResponse.fromJson(response); - } - - /// The homeserver must check that the given email address is not already associated - /// with an account on this homeserver. The homeserver should validate the email - /// itself, either by sending a validation email itself or by using a service it - /// has control over. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register-email-requesttoken - Future requestEmailToken( - String email, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/register/email/requestToken', - data: { - 'email': email, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// The homeserver must check that the given phone number is not already associated with an - /// account on this homeserver. The homeserver should validate the phone number itself, - /// either by sending a validation message itself or by using a service it has control over. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register-msisdn-requesttoken - Future requestMsisdnToken( - String country, - String phoneNumber, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/register/msisdn/requestToken', - data: { - 'country': country, - 'phone_number': phoneNumber, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// Changes the password for an account on this homeserver. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password - Future changePassword( - String newPassword, { - AuthenticationData auth, - }) async { - await request(RequestType.POST, '/client/r0/account/password', data: { - 'new_password': newPassword, - if (auth != null) 'auth': auth.toJson(), - }); - return; - } - - /// The homeserver must check that the given email address is associated with - /// an account on this homeserver. This API should be used to request - /// validation tokens when authenticating for the /account/password endpoint. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password-email-requesttoken - Future resetPasswordUsingEmail( - String email, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/account/password/email/requestToken', - data: { - 'email': email, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// The homeserver must check that the given phone number is associated with - /// an account on this homeserver. This API should be used to request validation - /// tokens when authenticating for the /account/password endpoint. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password-msisdn-requesttoken - Future resetPasswordUsingMsisdn( - String country, - String phoneNumber, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/account/password/msisdn/requestToken', - data: { - 'country': country, - 'phone_number': phoneNumber, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-deactivate - Future deactivateAccount({ - String idServer, - AuthenticationData auth, - }) async { - final response = - await request(RequestType.POST, '/client/r0/account/deactivate', data: { - if (idServer != null) 'id_server': idServer, - if (auth != null) 'auth': auth.toJson(), - }); - - return IdServerUnbindResult.values.firstWhere( - (i) => describeEnum(i) == response['id_server_unbind_result'], - ); - } - - Future usernameAvailable(String username) async { - final response = await request( - RequestType.GET, - '/client/r0/register/available?username=$username', - ); - return response['available']; - } - - /// Gets a list of the third party identifiers that the homeserver has - /// associated with the user's account. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available - Future> requestThirdPartyIdentifiers() async { - final response = await request( - RequestType.GET, - '/client/r0/account/3pid', - ); - return (response['threepids'] as List) - .map((item) => ThirdPartyIdentifier.fromJson(item)) - .toList(); - } - - /// Adds contact information to the user's account. Homeservers - /// should use 3PIDs added through this endpoint for password resets - /// instead of relying on the identity server. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-add - Future addThirdPartyIdentifier( - String clientSecret, - String sid, { - AuthenticationData auth, - }) async { - await request(RequestType.POST, '/client/r0/account/3pid/add', data: { - 'sid': sid, - 'client_secret': clientSecret, - if (auth != null) 'auth': auth.toJson(), - }); - return; - } - - /// Binds a 3PID to the user's account through the specified identity server. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind - Future bindThirdPartyIdentifier( - String clientSecret, - String sid, - String idServer, - String idAccessToken, - ) async { - await request(RequestType.POST, '/client/r0/account/3pid/bind', data: { - 'sid': sid, - 'client_secret': clientSecret, - 'id_server': idServer, - 'id_access_token': idAccessToken, - }); - return; - } - - /// Removes a third party identifier from the user's account. This might not cause an unbind of the identifier from the identity server. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-delete - Future deleteThirdPartyIdentifier( - String address, - ThirdPartyIdentifierMedium medium, { - String idServer, - }) async { - final response = await request( - RequestType.POST, '/client/r0/account/3pid/delete', - data: { - 'address': address, - 'medium': describeEnum(medium), - if (idServer != null) 'id_server': idServer, - }); - return IdServerUnbindResult.values.firstWhere( - (i) => describeEnum(i) == response['id_server_unbind_result'], - ); - } - - /// Removes a user's third party identifier from the provided identity server without removing it from the homeserver. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-unbind - Future unbindThirdPartyIdentifier( - String address, - ThirdPartyIdentifierMedium medium, - String idServer, - ) async { - final response = await request( - RequestType.POST, '/client/r0/account/3pid/unbind', - data: { - 'address': address, - 'medium': describeEnum(medium), - 'id_server': idServer, - }); - return IdServerUnbindResult.values.firstWhere( - (i) => describeEnum(i) == response['id_server_unbind_result'], - ); - } - - /// This API should be used to request validation tokens when adding an email address to an account. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-email-requesttoken - Future requestEmailValidationToken( - String email, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/account/3pid/email/requestToken', - data: { - 'email': email, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// This API should be used to request validation tokens when adding a phone number to an account. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-msisdn-requesttoken - Future requestMsisdnValidationToken( - String country, - String phoneNumber, - String clientSecret, - int sendAttempt, { - String nextLink, - String idServer, - String idAccessToken, - }) async { - final response = await request( - RequestType.POST, '/client/r0/account/3pid/msisdn/requestToken', - data: { - 'country': country, - 'phone_number': phoneNumber, - 'send_attempt': sendAttempt, - 'client_secret': clientSecret, - if (nextLink != null) 'next_link': nextLink, - if (idServer != null) 'id_server': idServer, - if (idAccessToken != null) 'id_access_token': idAccessToken, - }); - return RequestTokenResponse.fromJson(response); - } - - /// Gets information about the owner of a given access token. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-account-whoami - Future whoAmI() async { - final response = await request( - RequestType.GET, - '/client/r0/account/whoami', - ); - return response['user_id']; - } - - /// Gets information about the server's supported feature set and other relevant capabilities. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities - Future requestServerCapabilities() async { - final response = await request( - RequestType.GET, - '/client/r0/capabilities', - ); - return ServerCapabilities.fromJson(response['capabilities']); - } - - /// Uploads a new filter definition to the homeserver. Returns a filter ID that may be used - /// in future requests to restrict which events are returned to the client. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-userid-filter - Future uploadFilter( - String userId, - Filter filter, - ) async { - final response = await request( - RequestType.POST, - '/client/r0/user/${Uri.encodeComponent(userId)}/filter', - data: filter.toJson(), - ); - return response['filter_id']; - } - - /// Download a filter - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-userid-filter - Future downloadFilter(String userId, String filterId) async { - final response = await request( - RequestType.GET, - '/client/r0/user/${Uri.encodeComponent(userId)}/filter/${Uri.encodeComponent(filterId)}', - ); - return Filter.fromJson(response); - } - - /// Synchronise the client's state with the latest state on the server. Clients use this API when - /// they first log in to get an initial snapshot of the state on the server, and then continue to - /// call this API to get incremental deltas to the state, and to receive new messages. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-sync - Future sync({ - String filter, - String since, - bool fullState, - PresenceType setPresence, - int timeout, - }) async { - final response = await request( - RequestType.GET, - '/client/r0/sync', - query: { - if (filter != null) 'filter': filter, - if (since != null) 'since': since, - if (fullState != null) 'full_state': fullState.toString(), - if (setPresence != null) 'set_presence': describeEnum(setPresence), - if (timeout != null) 'timeout': timeout.toString(), - }, - ); - return SyncUpdate.fromJson(response); - } - - /// Get a single event based on roomId/eventId. You must have permission to - /// retrieve this event e.g. by being a member in the room for this event. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-event-eventid - Future requestEvent(String roomId, String eventId) async { - final response = await request( - RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/event/${Uri.encodeComponent(eventId)}', - ); - return MatrixEvent.fromJson(response); - } - - /// Looks up the contents of a state event in a room. If the user is joined to the room then the - /// state is taken from the current state of the room. If the user has left the room then the - /// state is taken from the state of the room when they left. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey - Future> requestStateContent( - String roomId, String eventType, - [String stateKey]) async { - var url = - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/'; - if (stateKey != null) { - url += Uri.encodeComponent(stateKey); - } - final response = await request( - RequestType.GET, - url, - ); - return response; - } - - /// Get the state events for the current state of a room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-state - Future> requestStates(String roomId) async { - final response = await request( - RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/state', - ); - return (response['chunk'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList(); - } - - /// Get the list of members for this room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members - Future> requestMembers( - String roomId, { - String at, - Membership membership, - Membership notMembership, - }) async { - final response = await request( - RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/members', - query: { - if (at != null) 'at': at, - if (membership != null) 'membership': describeEnum(membership), - if (notMembership != null) - 'not_membership': describeEnum(notMembership), - }, - ); - return (response['chunk'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList(); - } - - /// This API returns a map of MXIDs to member info objects for members of the room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members - Future> requestJoinedMembers(String roomId) async { - final response = await request( - RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/joined_members', - ); - return (response['joined'] as Map).map( - (k, v) => MapEntry(k, Profile.fromJson(v)), - ); - } - - /// This API returns a list of message and state events for a room. It uses pagination query - /// parameters to paginate history in the room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-messages - Future requestMessages( - String roomId, - String from, - Direction dir, { - String to, - int limit, - String filter, - }) async { - final response = await request(RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/messages', - query: { - 'from': from, - 'dir': describeEnum(dir), - if (to != null) 'to': to, - if (limit != null) 'limit': limit.toString(), - if (filter != null) 'filter': filter, - }); - return TimelineHistoryResponse.fromJson(response); - } - - /// State events can be sent using this endpoint. - /// https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey - Future sendState( - String roomId, - String eventType, - Map content, [ - String stateKey = '', - ]) async { - final response = await request(RequestType.PUT, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}', - data: content); - return response['event_id']; - } - - /// This endpoint is used to send a message event to a room. - /// Message events allow access to historical events and pagination, - /// making them suited for "once-off" activity in a room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid - Future sendMessage( - String roomId, - String eventType, - String txnId, - Map content, - ) async { - final response = await request(RequestType.PUT, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/send/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}', - data: content); - return response['event_id']; - } - - /// Strips all information out of an event which isn't critical to the integrity of - /// the server-side representation of the room. - /// https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid - Future redact( - String roomId, - String eventId, - String txnId, { - String reason, - }) async { - final response = await request(RequestType.PUT, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/redact/${Uri.encodeComponent(eventId)}/${Uri.encodeComponent(txnId)}', - data: { - if (reason != null) 'reason': reason, - }); - return response['event_id']; - } - - Future createRoom({ - Visibility visibility, - String roomAliasName, - String name, - String topic, - List invite, - List> invite3pid, - String roomVersion, - Map creationContent, - List> initialState, - CreateRoomPreset preset, - bool isDirect, - Map powerLevelContentOverride, - }) async { - final response = - await request(RequestType.POST, '/client/r0/createRoom', data: { - if (visibility != null) 'visibility': describeEnum(visibility), - if (roomAliasName != null) 'room_alias_name': roomAliasName, - if (name != null) 'name': name, - if (topic != null) 'topic': topic, - if (invite != null) 'invite': invite, - if (invite3pid != null) 'invite_3pid': invite3pid, - if (roomVersion != null) 'room_version': roomVersion, - if (creationContent != null) 'creation_content': creationContent, - if (initialState != null) 'initial_state': initialState, - if (preset != null) 'preset': describeEnum(preset), - if (isDirect != null) 'is_direct': isDirect, - if (powerLevelContentOverride != null) - 'power_level_content_override': powerLevelContentOverride, - }); - return response['room_id']; - } - - /// Create a new mapping from room alias to room ID. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-directory-room-roomalias - Future createRoomAlias(String alias, String roomId) async { - await request( - RequestType.PUT, - '/client/r0/directory/room/${Uri.encodeComponent(alias)}', - data: {'room_id': roomId}, - ); - return; - } - - /// 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 requestRoomAliasInformations( - String alias) async { - final response = await request( - RequestType.GET, - '/client/r0/directory/room/${Uri.encodeComponent(alias)}', - ); - return RoomAliasInformations.fromJson(response); - } - - /// Remove a mapping of room alias to room ID. - /// https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-directory-room-roomalias - Future removeRoomAlias(String alias) async { - await request( - RequestType.DELETE, - '/client/r0/directory/room/${Uri.encodeComponent(alias)}', - ); - return; - } - - /// Get a list of aliases maintained by the local server for the given room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-aliases - Future> requestRoomAliases(String roomId) async { - final response = await request( - RequestType.GET, - '/client/r0/room/${Uri.encodeComponent(roomId)}/aliases', - ); - return List.from(response['aliases']); - } - - /// This API returns a list of the user's current rooms. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-joined-rooms - Future> requestJoinedRooms() async { - final response = await request( - RequestType.GET, - '/client/r0/joined_rooms', - ); - return List.from(response['joined_rooms']); - } - - /// This API invites a user to participate in a particular room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-invite - Future inviteToRoom(String roomId, String userId) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/invite', - data: { - 'user_id': userId, - }, - ); - return; - } - - /// This API starts a user participating in a particular room, if that user is allowed to participate in that room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-invite - Future joinRoom( - String roomId, { - String thirdPidSignedSender, - String thirdPidSignedmxid, - String thirdPidSignedToken, - Map thirdPidSignedSiganture, - }) async { - final response = await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/join', - data: { - if (thirdPidSignedSiganture != null) - 'third_party_signed': { - 'sender': thirdPidSignedSender, - 'mxid': thirdPidSignedmxid, - 'token': thirdPidSignedToken, - 'signatures': thirdPidSignedSiganture, - } - }, - ); - return response['room_id']; - } - - /// This API starts a user participating in a particular room, if that user is allowed to participate in that room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-join-roomidoralias - Future joinRoomOrAlias( - String roomIdOrAlias, { - List servers, - String thirdPidSignedSender, - String thirdPidSignedmxid, - String thirdPidSignedToken, - Map thirdPidSignedSiganture, - }) async { - var action = '/client/r0/join/${Uri.encodeComponent(roomIdOrAlias)}'; - final queryPart = servers - ?.map((x) => 'server_name=${Uri.encodeQueryComponent(x)}') - ?.join('&'); - if (queryPart != null && queryPart != '') { - action += '?' + queryPart; - } - final response = await request( - RequestType.POST, - action, - data: { - if (thirdPidSignedSiganture != null) - 'third_party_signed': { - 'sender': thirdPidSignedSender, - 'mxid': thirdPidSignedmxid, - 'token': thirdPidSignedToken, - 'signatures': thirdPidSignedSiganture, - } - }, - ); - return response['room_id']; - } - - /// This API stops a user participating in a particular room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-leave - Future leaveRoom(String roomId) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/leave', - ); - return; - } - - /// This API stops a user remembering about a particular room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-forget - Future forgetRoom(String roomId) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/forget', - ); - return; - } - - /// Kick a user from the room. - /// The caller must have the required power level in order to perform this operation. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-kick - Future kickFromRoom(String roomId, String userId, - {String reason}) async { - await request(RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/kick', - data: { - 'user_id': userId, - if (reason != null) 'reason': reason, - }); - return; - } - - /// Ban a user in the room. If the user is currently in the room, also kick them. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-ban - Future banFromRoom(String roomId, String userId, - {String reason}) async { - await request( - RequestType.POST, '/client/r0/rooms/${Uri.encodeComponent(roomId)}/ban', - data: { - 'user_id': userId, - if (reason != null) 'reason': reason, - }); - return; - } - - /// Unban a user from the room. This allows them to be invited to the room, and join if they - /// would otherwise be allowed to join according to its join rules. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-unban - Future unbanInRoom(String roomId, String userId) async { - await request(RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/unban', - data: { - 'user_id': userId, - }); - return; - } - - /// Gets the visibility of a given room on the server's public room directory. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-directory-list-room-roomid - Future requestRoomVisibility(String roomId) async { - final response = await request( - RequestType.GET, - '/client/r0/directory/list/room/${Uri.encodeComponent(roomId)}', - ); - return Visibility.values - .firstWhere((v) => describeEnum(v) == response['visibility']); - } - - /// Sets the visibility of a given room in the server's public room directory. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-directory-list-room-roomid - Future setRoomVisibility(String roomId, Visibility visibility) async { - await request( - RequestType.PUT, - '/client/r0/directory/list/room/${Uri.encodeComponent(roomId)}', - data: { - 'visibility': describeEnum(visibility), - }, - ); - return; - } - - /// Lists the public rooms on the server. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-publicrooms - Future requestPublicRooms({ - int limit, - String since, - String server, - }) async { - final response = await request( - RequestType.GET, - '/client/r0/publicRooms', - query: { - if (limit != null) 'limit': limit.toString(), - if (since != null) 'since': since, - if (server != null) 'server': server, - }, - ); - return PublicRoomsResponse.fromJson(response); - } - - /// Lists the public rooms on the server, with optional filter. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-publicrooms - Future searchPublicRooms({ - String genericSearchTerm, - int limit, - String since, - String server, - bool includeAllNetworks, - String thirdPartyInstanceId, - }) async { - final response = await request( - RequestType.POST, - '/client/r0/publicRooms', - query: { - if (server != null) 'server': server, - }, - data: { - if (limit != null) 'limit': limit, - if (since != null) 'since': since, - if (includeAllNetworks != null) - 'include_all_networks': includeAllNetworks, - if (thirdPartyInstanceId != null) - 'third_party_instance_id': thirdPartyInstanceId, - if (genericSearchTerm != null) - 'filter': { - 'generic_search_term': genericSearchTerm, - }, - }, - ); - return PublicRoomsResponse.fromJson(response); - } - - /// Performs a search for users. The homeserver may determine which subset of users are searched, - /// however the homeserver MUST at a minimum consider the users the requesting user shares a - /// room with and those who reside in public rooms (known to the homeserver). The search MUST - /// consider local users to the homeserver, and SHOULD query remote users as part of the search. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-user-directory-search - Future searchUser( - String searchTerm, { - int limit, - }) async { - final response = await request( - RequestType.POST, - '/client/r0/user_directory/search', - data: { - 'search_term': searchTerm, - if (limit != null) 'limit': limit, - }, - ); - return UserSearchResult.fromJson(response); - } - - /// This API sets the given user's display name. You must have permission to - /// set this user's display name, e.g. you need to have their access_token. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-profile-userid-displayname - Future setDisplayname(String userId, String displayname) async { - await request( - RequestType.PUT, - '/client/r0/profile/${Uri.encodeComponent(userId)}/displayname', - data: { - 'displayname': displayname, - }, - ); - return; - } - - /// Get the user's display name. This API may be used to fetch the user's own - /// displayname or to query the name of other users; either locally or on remote homeservers. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-profile-userid-displayname - Future requestDisplayname(String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/profile/${Uri.encodeComponent(userId)}/displayname', - ); - return response['displayname']; - } - - /// This API sets the given user's avatar URL. You must have permission to set - /// this user's avatar URL, e.g. you need to have their access_token. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-profile-userid-avatar-url - Future setAvatarUrl(String userId, Uri avatarUrl) async { - await request( - RequestType.PUT, - '/client/r0/profile/${Uri.encodeComponent(userId)}/avatar_url', - data: { - 'avatar_url': avatarUrl.toString(), - }, - ); - return; - } - - /// Get the user's avatar URL. This API may be used to fetch the user's own avatar URL or to - /// query the URL of other users; either locally or on remote homeservers. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-profile-userid-avatar-url - Future requestAvatarUrl(String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/profile/${Uri.encodeComponent(userId)}/avatar_url', - ); - return Uri.parse(response['avatar_url']); - } - - /// Get the combined profile information for this user. This API may be used to fetch the user's - /// own profile information or other users; either locally or on remote homeservers. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-profile-userid-avatar-url - Future requestProfile(String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/profile/${Uri.encodeComponent(userId)}', - ); - return Profile.fromJson(response); - } - - /// This API provides credentials for the client to use when initiating calls. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-voip-turnserver - Future requestTurnServerCredentials() async { - final response = await request( - RequestType.GET, - '/client/r0/voip/turnServer', - ); - return TurnServerCredentials.fromJson(response); - } - - /// This tells the server that the user is typing for the next N milliseconds - /// where N is the value specified in the timeout key. Alternatively, if typing is false, - /// it tells the server that the user has stopped typing. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-typing-userid - Future sendTypingNotification( - String userId, - String roomId, - bool typing, { - int timeout, - }) async { - await request(RequestType.PUT, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/typing/${Uri.encodeComponent(userId)}', - data: { - 'typing': typing, - if (timeout != null) 'timeout': timeout, - }); - return; - } - - /// This API updates the marker for the given receipt type to the event ID specified. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid - /// - Future sendReceiptMarker(String roomId, String eventId) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/receipt/m.read/${Uri.encodeComponent(eventId)}', - ); - return; - } - - /// Sets the position of the read marker for a given room, and optionally the read receipt's location. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-read-markers - Future sendReadMarker(String roomId, String eventId, - {String readReceiptLocationEventId}) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/read_markers', - data: { - 'm.fully_read': eventId, - if (readReceiptLocationEventId != null) - 'm.read': readReceiptLocationEventId, - }, - ); - return; - } - - /// This API sets the given user's presence state. When setting the status, - /// the activity time is updated to reflect that activity; the client does not need - /// to specify the last_active_ago field. You cannot set the presence state of another user. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-presence-userid-status - Future sendPresence( - String userId, - PresenceType presenceType, { - String statusMsg, - }) async { - await request( - RequestType.PUT, - '/client/r0/presence/${Uri.encodeComponent(userId)}/status', - data: { - 'presence': describeEnum(presenceType), - if (statusMsg != null) 'status_msg': statusMsg, - }, - ); - return; - } - - /// Get the given user's presence state. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-presence-userid-status - Future requestPresence(String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/presence/${Uri.encodeComponent(userId)}/status', - ); - return PresenceContent.fromJson(response); - } - - /// Uploads a file with the name [fileName] as base64 encoded to the server - /// and returns the mxc url as a string. - /// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-media-r0-upload - Future upload(Uint8List file, String fileName, - {String contentType}) async { - fileName = fileName.split('/').last; - var headers = {}; - headers['Authorization'] = 'Bearer $accessToken'; - headers['Content-Type'] = - contentType ?? lookupMimeType(fileName, headerBytes: file); - fileName = Uri.encodeQueryComponent(fileName); - final url = - '${homeserver.toString()}/_matrix/media/r0/upload?filename=$fileName'; - final streamedRequest = http.StreamedRequest('POST', Uri.parse(url)) - ..headers.addAll(headers); - streamedRequest.contentLength = await file.length; - streamedRequest.sink.add(file); - streamedRequest.sink.close(); - var streamedResponse = _testMode ? null : await streamedRequest.send(); - Map jsonResponse = json.decode( - String.fromCharCodes(_testMode - ? ((fileName == 'file.jpeg') - ? '{"content_uri": "mxc://example.com/AQwafuaFswefuhsfAFAgsw"}' - : '{"errcode":"M_FORBIDDEN","error":"Cannot upload this content"}') - .codeUnits - : await streamedResponse.stream.first), - ); - if (!(jsonResponse['content_uri'] is String)) { - throw MatrixException.fromJson(jsonResponse); - } - return jsonResponse['content_uri']; - } - - /// Get information about a URL for the client. Typically this is called when a client sees a - /// URL in a message and wants to render a preview for the user. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-media-r0-preview-url - Future requestOpenGraphDataForUrl(Uri url, {int ts}) async { - var action = - '${homeserver.toString()}/_matrix/media/r0/preview_url?url=${Uri.encodeQueryComponent(url.toString())}'; - if (ts != null) { - action += '&ts=${Uri.encodeQueryComponent(ts.toString())}'; - } - final response = await httpClient.get(action); - final rawJson = json.decode(response.body.isEmpty ? '{}' : response.body); - return OpenGraphData.fromJson(rawJson); - } - - /// This endpoint allows clients to retrieve the configuration of the content repository, such as upload limitations. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-media-r0-config - Future requestMaxUploadSize() async { - var action = '${homeserver.toString()}/_matrix/media/r0/config'; - final response = await httpClient.get(action); - final rawJson = json.decode(response.body.isEmpty ? '{}' : response.body); - return rawJson['m.upload.size']; - } - - /// This endpoint is used to send send-to-device events to a set of client devices. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-sendtodevice-eventtype-txnid - Future sendToDevice( - String eventType, - String txnId, - Map>> messages, - ) async { - await request( - RequestType.PUT, - '/client/r0/sendToDevice/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}', - data: { - 'messages': messages, - }, - ); - return; - } - - /// Gets information about all devices for the current user. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices - Future> requestDevices() async { - final response = await request( - RequestType.GET, - '/client/r0/devices', - ); - return (response['devices'] as List) - .map((i) => Device.fromJson(i)) - .toList(); - } - - /// Gets information on a single device, by device id. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices-deviceid - Future requestDevice(String deviceId) async { - final response = await request( - RequestType.GET, - '/client/r0/devices/${Uri.encodeComponent(deviceId)}', - ); - return Device.fromJson(response); - } - - /// Updates the metadata on the given device. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-devices-deviceid - Future setDeviceMetadata(String deviceId, {String displayName}) async { - await request( - RequestType.PUT, '/client/r0/devices/${Uri.encodeComponent(deviceId)}', - data: { - if (displayName != null) 'display_name': displayName, - }); - return; - } - - /// Deletes the given device, and invalidates any access token associated with it. - /// https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-devices-deviceid - Future deleteDevice(String deviceId, {AuthenticationData auth}) async { - await request(RequestType.DELETE, - '/client/r0/devices/${Uri.encodeComponent(deviceId)}', - data: { - if (auth != null) 'auth': auth.toJson(), - }); - return; - } - - /// Deletes the given devices, and invalidates any access token associated with them. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-delete-devices - Future deleteDevices(List deviceIds, - {AuthenticationData auth}) async { - await request(RequestType.POST, '/client/r0/delete_devices', data: { - 'devices': deviceIds, - if (auth != null) 'auth': auth.toJson(), - }); - return; - } - - /// Publishes end-to-end encryption keys for the device. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query - Future> uploadDeviceKeys( - {MatrixDeviceKeys deviceKeys, Map oneTimeKeys}) async { - final response = await request( - RequestType.POST, - '/client/r0/keys/upload', - data: { - if (deviceKeys != null) 'device_keys': deviceKeys.toJson(), - if (oneTimeKeys != null) 'one_time_keys': oneTimeKeys, - }, - ); - return Map.from(response['one_time_key_counts']); - } - - /// Returns the current devices and identity keys for the given users. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query - Future requestDeviceKeys( - Map deviceKeys, { - int timeout, - String token, - }) async { - final response = await request( - RequestType.POST, - '/client/r0/keys/query', - data: { - 'device_keys': deviceKeys, - if (timeout != null) 'timeout': timeout, - if (token != null) 'token': token, - }, - ); - return KeysQueryResponse.fromJson(response); - } - - /// Claims one-time keys for use in pre-key messages. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-claim - Future requestOneTimeKeys( - Map> oneTimeKeys, { - int timeout, - }) async { - final response = await request( - RequestType.POST, - '/client/r0/keys/claim', - data: { - 'one_time_keys': oneTimeKeys, - if (timeout != null) 'timeout': timeout, - }, - ); - return OneTimeKeysClaimResponse.fromJson(response); - } - - /// Gets a list of users who have updated their device identity keys since a previous sync token. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-upload - Future requestDeviceListsUpdate( - String from, String to) async { - final response = await request( - RequestType.GET, - '/client/r0/keys/changes?from=${Uri.encodeQueryComponent(from)}&to=${Uri.encodeQueryComponent(to)}', - ); - return DeviceListsUpdate.fromJson(response); - } - - /// Uploads your own cross-signing keys. - /// https://github.com/matrix-org/matrix-doc/pull/2536 - Future uploadDeviceSigningKeys({ - MatrixCrossSigningKey masterKey, - MatrixCrossSigningKey selfSigningKey, - MatrixCrossSigningKey userSigningKey, - AuthenticationData auth, - }) async { - await request( - RequestType.POST, - '/client/unstable/keys/device_signing/upload', - data: { - if (masterKey != null) 'master_key': masterKey.toJson(), - if (selfSigningKey != null) 'self_signing_key': selfSigningKey.toJson(), - if (userSigningKey != null) 'user_signing_key': userSigningKey.toJson(), - if (auth != null) 'auth': auth.toJson(), - }, - ); - } - - /// Uploads new signatures of keys - /// https://github.com/matrix-org/matrix-doc/pull/2536 - Future uploadKeySignatures( - List keys) async { - final payload = {}; - for (final key in keys) { - if (key.identifier == null || - key.signatures == null || - key.signatures.isEmpty) { - continue; - } - if (!payload.containsKey(key.userId)) { - payload[key.userId] = {}; - } - if (payload[key.userId].containsKey(key.identifier)) { - // we need to merge signature objects - payload[key.userId][key.identifier]['signatures'] - .addAll(key.signatures); - } else { - // we can just add signatures - payload[key.userId][key.identifier] = key.toJson(); - } - } - final response = await request( - RequestType.POST, - '/client/r0/keys/signatures/upload', - data: payload, - ); - return UploadKeySignaturesResponse.fromJson(response); - } - - /// Gets all currently active pushers for the authenticated user. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushers - Future> requestPushers() async { - final response = await request( - RequestType.GET, - '/client/r0/pushers', - ); - return (response['pushers'] as List) - .map((i) => Pusher.fromJson(i)) - .toList(); - } - - /// This endpoint allows the creation, modification and deletion of pushers - /// for this user ID. The behaviour of this endpoint varies depending on the - /// values in the JSON body. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-pushers-set - Future setPusher(Pusher pusher, {bool append}) async { - var data = pusher.toJson(); - if (append != null) { - data['append'] = append; - } - await request( - RequestType.POST, - '/client/r0/pushers/set', - data: data, - ); - return; - } - - /// This API is used to paginate through the list of events that the user has - /// been, or would have been notified about. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-notifications - Future requestNotifications({ - String from, - int limit, - String only, - }) async { - final response = await request( - RequestType.GET, - '/client/r0/notifications', - query: { - if (from != null) 'from': from, - if (limit != null) 'limit': limit.toString(), - if (only != null) 'only': only, - }, - ); - return NotificationsQueryResponse.fromJson(response); - } - - /// Retrieve all push rulesets for this user. Clients can "drill-down" - /// on the rulesets by suffixing a scope to this path e.g. /pushrules/global/. - /// This will return a subset of this data under the specified key e.g. the global key. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushrules - Future requestPushRules() async { - final response = await request( - RequestType.GET, - '/client/r0/pushrules', - ); - return PushRuleSet.fromJson(response['global']); - } - - /// Retrieve a single specified push rule. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushrules-scope-kind-ruleid - Future requestPushRule( - String scope, - PushRuleKind kind, - String ruleId, - ) async { - final response = await request( - RequestType.GET, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}', - ); - return PushRule.fromJson(response); - } - - /// This endpoint removes the push rule defined in the path. - /// https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-pushrules-scope-kind-ruleid - Future deletePushRule( - String scope, - PushRuleKind kind, - String ruleId, - ) async { - await request( - RequestType.DELETE, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}', - ); - return; - } - - /// This endpoint allows the creation, modification and deletion of pushers for this user ID. - /// The behaviour of this endpoint varies depending on the values in the JSON body. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-pushrules-scope-kind-ruleid - Future setPushRule( - String scope, - PushRuleKind kind, - String ruleId, - List actions, { - String before, - String after, - List conditions, - String pattern, - }) async { - await request(RequestType.PUT, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}', - query: { - if (before != null) 'before': before, - if (after != null) 'after': after, - }, - data: { - 'actions': actions.map(describeEnum).toList(), - if (conditions != null) - 'conditions': conditions.map((c) => c.toJson()).toList(), - if (pattern != null) 'pattern': pattern, - }); - return; - } - - /// This endpoint gets whether the specified push rule is enabled. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushrules-scope-kind-ruleid-enabled - Future requestPushRuleEnabled( - String scope, - PushRuleKind kind, - String ruleId, - ) async { - final response = await request( - RequestType.GET, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}/enabled', - ); - return response['enabled']; - } - - /// This endpoint allows clients to enable or disable the specified push rule. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-pushrules-scope-kind-ruleid-enabled - Future enablePushRule( - String scope, - PushRuleKind kind, - String ruleId, - bool enabled, - ) async { - await request( - RequestType.PUT, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}/enabled', - data: {'enabled': enabled}, - ); - return; - } - - /// This endpoint get the actions for the specified push rule. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushrules-scope-kind-ruleid-actions - Future> requestPushRuleActions( - String scope, - PushRuleKind kind, - String ruleId, - ) async { - final response = await request( - RequestType.GET, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}/actions', - ); - return (response['actions'] as List) - .map((i) => - PushRuleAction.values.firstWhere((a) => describeEnum(a) == i)) - .toList(); - } - - /// This endpoint allows clients to change the actions of a push rule. This can be used to change the actions of builtin rules. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-pushrules-scope-kind-ruleid-actions - Future setPushRuleActions( - String scope, - PushRuleKind kind, - String ruleId, - List actions, - ) async { - await request( - RequestType.PUT, - '/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(describeEnum(kind))}/${Uri.encodeComponent(ruleId)}/actions', - data: {'actions': actions.map((a) => describeEnum(a)).toList()}, - ); - return; - } - - /// 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. - Future> globalSearch(Map query) async { - return await request( - RequestType.POST, - '/client/r0/search', - data: query, - ); - } - - /// This will listen for new events related to a particular room and return them to the - /// caller. This will block until an event is received, or until the timeout is reached. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-events - Future requestEvents({ - String from, - int timeout, - String roomId, - }) async { - final response = - await request(RequestType.GET, '/client/r0/events', query: { - if (from != null) 'from': from, - if (timeout != null) 'timeout': timeout.toString(), - if (roomId != null) 'roomId': roomId, - }); - return EventsSyncUpdate.fromJson(response); - } - - /// List the tags set by a user on a room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-user-userid-rooms-roomid-tags - Future> requestRoomTags(String userId, String roomId) async { - final response = await request( - RequestType.GET, - '/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags', - ); - return (response['tags'] as Map).map( - (k, v) => MapEntry(k, Tag.fromJson(v)), - ); - } - - /// Add a tag to the room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag - Future addRoomTag( - String userId, - String roomId, - String tag, { - double order, - }) async { - await request(RequestType.PUT, - '/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}', - data: { - if (order != null) 'order': order, - }); - return; - } - - /// Remove a tag from the room. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag - Future removeRoomTag(String userId, String roomId, String tag) async { - await request( - RequestType.DELETE, - '/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}', - ); - return; - } - - /// Set some account_data for the client. This config is only visible to the user that set the account_data. - /// The config will be synced to clients in the top-level account_data. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-user-userid-account-data-type - Future setAccountData( - String userId, - String type, - Map content, - ) async { - await request( - RequestType.PUT, - '/client/r0/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}', - data: content, - ); - return; - } - - /// Get some account_data for the client. This config is only visible to the user that set the account_data. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-user-userid-account-data-type - Future> requestAccountData( - String userId, - String type, - ) async { - return await request( - RequestType.GET, - '/client/r0/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}', - ); - } - - /// Set some account_data for the client on a given room. This config is only visible to the user that set - /// the account_data. The config will be synced to clients in the per-room account_data. - /// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type - Future setRoomAccountData( - String userId, - String roomId, - String type, - Map content, - ) async { - await request( - RequestType.PUT, - '/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}', - data: content, - ); - return; - } - - /// Get some account_data for the client on a given room. This config is only visible to the user that set the account_data. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-user-userid-rooms-roomid-account-data-type - Future> requestRoomAccountData( - String userId, - String roomId, - String type, - ) async { - return await request( - RequestType.GET, - '/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}', - ); - } - - /// Gets information about a particular user. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid - Future requestWhoIsInfo(String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/admin/whois/${Uri.encodeComponent(userId)}', - ); - return WhoIsInfo.fromJson(response); - } - - /// This API returns a number of events that happened just before and after the specified event. - /// This allows clients to get the context surrounding an event. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-context-eventid - Future requestEventContext( - String roomId, - String eventId, { - int limit, - String filter, - }) async { - final response = await request(RequestType.GET, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/context/${Uri.encodeComponent(eventId)}', - query: { - if (filter != null) 'filter': filter, - if (limit != null) 'limit': limit.toString(), - }); - return EventContext.fromJson(response); - } - - /// Reports an event as inappropriate to the server, which may then notify the appropriate people. - /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-report-eventid - Future reportEvent( - String roomId, - String eventId, - String reason, - int score, - ) async { - await request(RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/report/${Uri.encodeComponent(eventId)}', - data: { - 'reason': reason, - 'score': score, - }); - return; - } - - /// Fetches the overall metadata about protocols supported by the homeserver. Includes - /// both the available protocols and all fields required for queries against each protocol. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-protocols - Future> requestSupportedProtocols() async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/protocols', - ); - return response.map((k, v) => MapEntry(k, SupportedProtocol.fromJson(v))); - } - - /// Fetches the metadata from the homeserver about a particular third party protocol. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-protocol-protocol - Future requestSupportedProtocol(String protocol) async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/protocol/${Uri.encodeComponent(protocol)}', - ); - return SupportedProtocol.fromJson(response); - } - - /// Requesting this endpoint with a valid protocol name results in a list of successful - /// mapping results in a JSON array. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-location-protocol - Future> requestThirdPartyLocations( - String protocol) async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/location/${Uri.encodeComponent(protocol)}', - ); - return (response['chunk'] as List) - .map((i) => ThirdPartyLocation.fromJson(i)) - .toList(); - } - - /// Retrieve a Matrix User ID linked to a user on the third party service, given a set of - /// user parameters. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-user-protocol - Future> requestThirdPartyUsers(String protocol) async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/user/${Uri.encodeComponent(protocol)}', - ); - return (response['chunk'] as List) - .map((i) => ThirdPartyUser.fromJson(i)) - .toList(); - } - - /// Retrieve an array of third party network locations from a Matrix room alias. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-location - Future> requestThirdPartyLocationsByAlias( - String alias) async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/location?alias=${Uri.encodeComponent(alias)}', - ); - return (response['chunk'] as List) - .map((i) => ThirdPartyLocation.fromJson(i)) - .toList(); - } - - /// Retrieve an array of third party users from a Matrix User ID. - /// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-user - Future> requestThirdPartyUsersByUserId( - String userId) async { - final response = await request( - RequestType.GET, - '/client/r0/thirdparty/user?userid=${Uri.encodeComponent(userId)}', - ); - return (response['chunk'] as List) - .map((i) => ThirdPartyUser.fromJson(i)) - .toList(); - } - - Future requestOpenIdCredentials(String userId) async { - final response = await request( - RequestType.POST, - '/client/r0/user/${Uri.encodeComponent(userId)}/openid/request_token', - data: {}, - ); - return OpenIdCredentials.fromJson(response); - } - - Future upgradeRoom(String roomId, String version) async { - await request( - RequestType.POST, - '/client/r0/rooms/${Uri.encodeComponent(roomId)}/upgrade', - data: {'new_version': version}, - ); - return; - } - - /// Create room keys backup - /// https://matrix.org/docs/spec/client_server/unstable#post-matrix-client-r0-room-keys-version - Future createRoomKeysBackup( - RoomKeysAlgorithmType algorithm, Map authData) async { - final ret = await request( - RequestType.POST, - '/client/unstable/room_keys/version', - data: { - 'algorithm': algorithm.algorithmString, - 'auth_data': authData, - }, - ); - return ret['version']; - } - - /// Gets a room key backup - /// https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-version - Future getRoomKeysBackup([String version]) async { - var url = '/client/unstable/room_keys/version'; - if (version != null) { - url += '/${Uri.encodeComponent(version)}'; - } - final ret = await request( - RequestType.GET, - url, - ); - return RoomKeysVersionResponse.fromJson(ret); - } - - /// Updates a room key backup - /// https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-version-version - Future updateRoomKeysBackup(String version, - RoomKeysAlgorithmType algorithm, Map authData) async { - await request( - RequestType.PUT, - '/client/unstable/room_keys/version/${Uri.encodeComponent(version)}', - data: { - 'algorithm': algorithm.algorithmString, - 'auth_data': authData, - 'version': version, - }, - ); - } - - /// Deletes a room key backup - /// https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-version-version - Future deleteRoomKeysBackup(String version) async { - await request( - RequestType.DELETE, - '/client/unstable/room_keys/version/${Uri.encodeComponent(version)}', - ); - } - - /// Stores a single room key - /// https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys-roomid-sessionid - Future storeRoomKeysSingleKey(String roomId, - String sessionId, String version, RoomKeysSingleKey session) async { - final ret = await request( - RequestType.PUT, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}?version=${Uri.encodeComponent(version)}', - data: session.toJson(), - ); - return RoomKeysUpdateResponse.fromJson(ret); - } - - /// Gets a single room key - /// https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys-roomid-sessionid - Future getRoomKeysSingleKey( - String roomId, String sessionId, String version) async { - final ret = await request( - RequestType.GET, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}?version=${Uri.encodeComponent(version)}', - ); - return RoomKeysSingleKey.fromJson(ret); - } - - /// Deletes a single room key - /// https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys-roomid-sessionid - Future deleteRoomKeysSingleKey( - String roomId, String sessionId, String version) async { - final ret = await request( - RequestType.DELETE, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}?version=${Uri.encodeComponent(version)}', - ); - return RoomKeysUpdateResponse.fromJson(ret); - } - - /// Stores room keys for a room - /// https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys-roomid - Future storeRoomKeysRoom( - String roomId, String version, RoomKeysRoom keys) async { - final ret = await request( - RequestType.PUT, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}?version=${Uri.encodeComponent(version)}', - data: keys.toJson(), - ); - return RoomKeysUpdateResponse.fromJson(ret); - } - - /// Gets room keys for a room - /// https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys-roomid - Future getRoomKeysRoom(String roomId, String version) async { - final ret = await request( - RequestType.GET, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}?version=${Uri.encodeComponent(version)}', - ); - return RoomKeysRoom.fromJson(ret); - } - - /// Deletes room keys for a room - /// https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys-roomid - Future deleteRoomKeysRoom( - String roomId, String version) async { - final ret = await request( - RequestType.DELETE, - '/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}?version=${Uri.encodeComponent(version)}', - ); - return RoomKeysUpdateResponse.fromJson(ret); - } - - /// Store multiple room keys - /// https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys - Future storeRoomKeys( - String version, RoomKeys keys) async { - final ret = await request( - RequestType.PUT, - '/client/unstable/room_keys/keys?version=${Uri.encodeComponent(version)}', - data: keys.toJson(), - ); - return RoomKeysUpdateResponse.fromJson(ret); - } - - /// get all room keys - /// https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys - Future getRoomKeys(String version) async { - final ret = await request( - RequestType.GET, - '/client/unstable/room_keys/keys?version=${Uri.encodeComponent(version)}', - ); - return RoomKeys.fromJson(ret); - } - - /// delete all room keys - /// https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys - Future deleteRoomKeys(String version) async { - final ret = await request( - RequestType.DELETE, - '/client/unstable/room_keys/keys?version=${Uri.encodeComponent(version)}', - ); - return RoomKeysUpdateResponse.fromJson(ret); - } -} diff --git a/lib/matrix_api/model/algorithm_types.dart b/lib/matrix_api/model/algorithm_types.dart deleted file mode 100644 index cc657d7b..00000000 --- a/lib/matrix_api/model/algorithm_types.dart +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -abstract class AlgorithmTypes { - static const String olmV1Curve25519AesSha2 = 'm.olm.v1.curve25519-aes-sha2'; - static const String megolmV1AesSha2 = 'm.megolm.v1.aes-sha2'; - static const String secretStorageV1AesHmcSha2 = - 'm.secret_storage.v1.aes-hmac-sha2'; - static const String megolmBackupV1Curve25519AesSha2 = - 'm.megolm_backup.v1.curve25519-aes-sha2'; - static const String pbkdf2 = 'm.pbkdf2'; -} diff --git a/lib/matrix_api/model/auth/authentication_data.dart b/lib/matrix_api/model/auth/authentication_data.dart deleted file mode 100644 index ad340400..00000000 --- a/lib/matrix_api/model/auth/authentication_data.dart +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class AuthenticationData { - String type; - String session; - - AuthenticationData({this.type, this.session}); - - AuthenticationData.fromJson(Map json) { - type = json['type']; - session = json['session']; - } - - Map toJson() { - final data = {}; - if (type != null) data['type'] = type; - if (session != null) data['session'] = session; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_identifier.dart b/lib/matrix_api/model/auth/authentication_identifier.dart deleted file mode 100644 index be5a4bfa..00000000 --- a/lib/matrix_api/model/auth/authentication_identifier.dart +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class AuthenticationIdentifier { - String type; - - AuthenticationIdentifier({this.type}); - - AuthenticationIdentifier.fromJson(Map json) { - type = json['type']; - } - - Map toJson() { - final data = {}; - data['type'] = type; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_password.dart b/lib/matrix_api/model/auth/authentication_password.dart deleted file mode 100644 index 0a95a7ba..00000000 --- a/lib/matrix_api/model/auth/authentication_password.dart +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'package:famedlysdk/matrix_api/model/auth/authentication_user_identifier.dart'; - -import 'authentication_data.dart'; -import 'authentication_identifier.dart'; -import 'authentication_phone_identifier.dart'; -import 'authentication_third_party_identifier.dart'; -import 'authentication_types.dart'; - -class AuthenticationPassword extends AuthenticationData { - String user; - String password; - - /// You may want to cast this as [AuthenticationUserIdentifier] or other - /// Identifier classes extending AuthenticationIdentifier. - AuthenticationIdentifier identifier; - - AuthenticationPassword( - {String session, this.password, this.user, this.identifier}) - : super( - type: AuthenticationTypes.password, - session: session, - ); - - AuthenticationPassword.fromJson(Map json) - : super.fromJson(json) { - user = json['user']; - password = json['password']; - identifier = AuthenticationIdentifier.fromJson(json['identifier']); - switch (identifier.type) { - case AuthenticationIdentifierTypes.userId: - identifier = AuthenticationUserIdentifier.fromJson(json['identifier']); - break; - case AuthenticationIdentifierTypes.phone: - identifier = AuthenticationPhoneIdentifier.fromJson(json['identifier']); - break; - case AuthenticationIdentifierTypes.thirdParty: - identifier = - AuthenticationThirdPartyIdentifier.fromJson(json['identifier']); - break; - } - } - - @override - Map toJson() { - final data = super.toJson(); - if (user != null) data['user'] = user; - data['password'] = password; - switch (identifier.type) { - case AuthenticationIdentifierTypes.userId: - data['identifier'] = - (identifier as AuthenticationUserIdentifier).toJson(); - break; - case AuthenticationIdentifierTypes.phone: - data['identifier'] = - (identifier as AuthenticationPhoneIdentifier).toJson(); - break; - case AuthenticationIdentifierTypes.thirdParty: - data['identifier'] = - (identifier as AuthenticationThirdPartyIdentifier).toJson(); - break; - default: - data['identifier'] = identifier.toJson(); - break; - } - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_phone_identifier.dart b/lib/matrix_api/model/auth/authentication_phone_identifier.dart deleted file mode 100644 index 452f01c2..00000000 --- a/lib/matrix_api/model/auth/authentication_phone_identifier.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_identifier.dart'; -import 'authentication_types.dart'; - -class AuthenticationPhoneIdentifier extends AuthenticationIdentifier { - String country; - String phone; - - AuthenticationPhoneIdentifier({this.country, this.phone}) - : super(type: AuthenticationIdentifierTypes.phone); - - AuthenticationPhoneIdentifier.fromJson(Map json) - : super.fromJson(json) { - country = json['country']; - phone = json['phone']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['country'] = country; - data['phone'] = phone; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_recaptcha.dart b/lib/matrix_api/model/auth/authentication_recaptcha.dart deleted file mode 100644 index 3d0816ad..00000000 --- a/lib/matrix_api/model/auth/authentication_recaptcha.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_data.dart'; -import 'authentication_types.dart'; - -class AuthenticationRecaptcha extends AuthenticationData { - String response; - - AuthenticationRecaptcha({String session, this.response}) - : super( - type: AuthenticationTypes.recaptcha, - session: session, - ); - - AuthenticationRecaptcha.fromJson(Map json) - : super.fromJson(json) { - response = json['response']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['response'] = response; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_third_party_identifier.dart b/lib/matrix_api/model/auth/authentication_third_party_identifier.dart deleted file mode 100644 index 5a4ab496..00000000 --- a/lib/matrix_api/model/auth/authentication_third_party_identifier.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_identifier.dart'; -import 'authentication_types.dart'; - -class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier { - String medium; - String address; - - AuthenticationThirdPartyIdentifier({this.medium, this.address}) - : super(type: AuthenticationIdentifierTypes.thirdParty); - - AuthenticationThirdPartyIdentifier.fromJson(Map json) - : super.fromJson(json) { - medium = json['medium']; - address = json['address']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['medium'] = medium; - data['address'] = address; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_three_pid_creds.dart b/lib/matrix_api/model/auth/authentication_three_pid_creds.dart deleted file mode 100644 index 1ddb45e7..00000000 --- a/lib/matrix_api/model/auth/authentication_three_pid_creds.dart +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_data.dart'; - -/// For email based identity: -/// https://matrix.org/docs/spec/client_server/r0.6.1#email-based-identity-homeserver -/// 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 { - List threepidCreds; - - AuthenticationThreePidCreds({String session, String type, this.threepidCreds}) - : super( - type: type, - session: session, - ); - - 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(); - } - } - - @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(); - return data; - } -} - -class ThreepidCreds { - String sid; - String clientSecret; - String idServer; - String idAccessToken; - - ThreepidCreds( - {this.sid, this.clientSecret, this.idServer, this.idAccessToken}); - - ThreepidCreds.fromJson(Map json) { - sid = json['sid']; - clientSecret = json['client_secret']; - idServer = json['id_server']; - idAccessToken = json['id_access_token']; - } - - Map toJson() { - final data = {}; - data['sid'] = sid; - data['client_secret'] = clientSecret; - data['id_server'] = idServer; - data['id_access_token'] = idAccessToken; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_token.dart b/lib/matrix_api/model/auth/authentication_token.dart deleted file mode 100644 index 23db3755..00000000 --- a/lib/matrix_api/model/auth/authentication_token.dart +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_data.dart'; -import 'authentication_types.dart'; - -class AuthenticationToken extends AuthenticationData { - String token; - String txnId; - - AuthenticationToken({String session, this.token, this.txnId}) - : super( - type: AuthenticationTypes.token, - session: session, - ); - - AuthenticationToken.fromJson(Map json) - : super.fromJson(json) { - token = json['token']; - txnId = json['txn_id']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['token'] = token; - data['txn_id'] = txnId; - return data; - } -} diff --git a/lib/matrix_api/model/auth/authentication_types.dart b/lib/matrix_api/model/auth/authentication_types.dart deleted file mode 100644 index 34e357f3..00000000 --- a/lib/matrix_api/model/auth/authentication_types.dart +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -abstract class AuthenticationTypes { - static const String password = 'm.login.password'; - static const String recaptcha = 'm.login.recaptcha'; - static const String token = 'm.login.token'; - static const String oauth2 = 'm.login.oauth2'; - static const String sso = 'm.login.sso'; - static const String emailIdentity = 'm.login.email.identity'; - static const String msisdn = 'm.login.msisdn'; - static const String dummy = 'm.login.dummy'; -} - -abstract class AuthenticationIdentifierTypes { - static const String userId = 'm.id.user'; - static const String thirdParty = 'm.id.thirdparty'; - static const String phone = 'm.id.phone'; -} diff --git a/lib/matrix_api/model/auth/authentication_user_identifier.dart b/lib/matrix_api/model/auth/authentication_user_identifier.dart deleted file mode 100644 index 66e6091e..00000000 --- a/lib/matrix_api/model/auth/authentication_user_identifier.dart +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'authentication_identifier.dart'; -import 'authentication_types.dart'; - -class AuthenticationUserIdentifier extends AuthenticationIdentifier { - String user; - - AuthenticationUserIdentifier({this.user}) - : super(type: AuthenticationIdentifierTypes.userId); - - AuthenticationUserIdentifier.fromJson(Map json) - : super.fromJson(json) { - user = json['user']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['user'] = user; - return data; - } -} diff --git a/lib/matrix_api/model/basic_event.dart b/lib/matrix_api/model/basic_event.dart deleted file mode 100644 index 7a91f559..00000000 --- a/lib/matrix_api/model/basic_event.dart +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -class BasicEvent { - String type; - Map content; - - BasicEvent({ - this.type, - this.content, - }); - - BasicEvent.fromJson(Map json) { - type = json['type']; - content = (json['content'] as Map).copy(); - } - Map toJson() { - final data = {}; - data['type'] = type; - data['content'] = content; - return data; - } -} diff --git a/lib/matrix_api/model/basic_event_with_sender.dart b/lib/matrix_api/model/basic_event_with_sender.dart deleted file mode 100644 index 0e50bd86..00000000 --- a/lib/matrix_api/model/basic_event_with_sender.dart +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'basic_event.dart'; - -class BasicEventWithSender extends BasicEvent { - String senderId; - - BasicEventWithSender(); - - BasicEventWithSender.fromJson(Map json) { - final basicEvent = BasicEvent.fromJson(json); - type = basicEvent.type; - content = basicEvent.content; - senderId = json['sender']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['sender'] = senderId; - return data; - } -} diff --git a/lib/matrix_api/model/basic_room_event.dart b/lib/matrix_api/model/basic_room_event.dart deleted file mode 100644 index de8ee75c..00000000 --- a/lib/matrix_api/model/basic_room_event.dart +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'basic_event.dart'; - -class BasicRoomEvent extends BasicEvent { - String roomId; - - BasicRoomEvent({ - this.roomId, - Map content, - String type, - }) : super( - content: content, - type: type, - ); - - BasicRoomEvent.fromJson(Map json) { - final basicEvent = BasicEvent.fromJson(json); - content = basicEvent.content; - type = basicEvent.type; - roomId = json['room_id']; - } - - @override - Map toJson() { - final data = super.toJson(); - if (roomId != null) data['room_id'] = roomId; - return data; - } -} diff --git a/lib/matrix_api/model/device.dart b/lib/matrix_api/model/device.dart deleted file mode 100644 index aa089a4b..00000000 --- a/lib/matrix_api/model/device.dart +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class Device { - String deviceId; - String displayName; - String lastSeenIp; - DateTime lastSeenTs; - - Device.fromJson(Map json) { - deviceId = json['device_id']; - displayName = json['display_name']; - lastSeenIp = json['last_seen_ip']; - lastSeenTs = DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0); - } - - Map toJson() { - final data = {}; - data['device_id'] = deviceId; - if (displayName != null) { - data['display_name'] = displayName; - } - if (lastSeenIp != null) { - data['last_seen_ip'] = lastSeenIp; - } - if (lastSeenTs != null) { - data['last_seen_ts'] = lastSeenTs.millisecondsSinceEpoch; - } - return data; - } -} diff --git a/lib/matrix_api/model/event_context.dart b/lib/matrix_api/model/event_context.dart deleted file mode 100644 index 9d23961c..00000000 --- a/lib/matrix_api/model/event_context.dart +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_event.dart'; - -class EventContext { - String end; - List eventsAfter; - MatrixEvent event; - List eventsBefore; - String start; - List state; - - EventContext.fromJson(Map json) { - end = json['end']; - if (json['events_after'] != null) { - eventsAfter = []; - json['events_after'].forEach((v) { - eventsAfter.add(MatrixEvent.fromJson(v)); - }); - } - event = json['event'] != null ? MatrixEvent.fromJson(json['event']) : null; - if (json['events_before'] != null) { - eventsBefore = []; - json['events_before'].forEach((v) { - eventsBefore.add(MatrixEvent.fromJson(v)); - }); - } - start = json['start']; - if (json['state'] != null) { - state = []; - json['state'].forEach((v) { - state.add(MatrixEvent.fromJson(v)); - }); - } - } - - Map toJson() { - final data = {}; - if (end != null) { - data['end'] = end; - } - if (eventsAfter != null) { - data['events_after'] = eventsAfter.map((v) => v.toJson()).toList(); - } - if (event != null) { - data['event'] = event.toJson(); - } - if (eventsBefore != null) { - data['events_before'] = eventsBefore.map((v) => v.toJson()).toList(); - } - data['start'] = start; - if (state != null) { - data['state'] = state.map((v) => v.toJson()).toList(); - } - return data; - } -} diff --git a/lib/matrix_api/model/event_types.dart b/lib/matrix_api/model/event_types.dart deleted file mode 100644 index 36b63a7d..00000000 --- a/lib/matrix_api/model/event_types.dart +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -abstract class EventTypes { - // Room timeline and state event types - static const String Message = 'm.room.message'; - static const String Sticker = 'm.sticker'; - static const String Reaction = 'm.reaction'; - static const String Redaction = 'm.room.redaction'; - static const String RoomAliases = 'm.room.aliases'; - static const String RoomCanonicalAlias = 'm.room.canonical_alias'; - static const String RoomCreate = 'm.room.create'; - static const String RoomJoinRules = 'm.room.join_rules'; - static const String RoomMember = 'm.room.member'; - static const String RoomPowerLevels = 'm.room.power_levels'; - static const String RoomName = 'm.room.name'; - static const String RoomPinnedEvents = 'm.room.pinned_events'; - static const String RoomTopic = 'm.room.topic'; - static const String RoomAvatar = 'm.room.avatar'; - static const String RoomTombstone = 'm.room.tombstone'; - static const String GuestAccess = 'm.room.guest_access'; - static const String HistoryVisibility = 'm.room.history_visibility'; - static const String Encryption = 'm.room.encryption'; - static const String Encrypted = 'm.room.encrypted'; - static const String CallInvite = 'm.call.invite'; - static const String CallAnswer = 'm.call.answer'; - static const String CallCandidates = 'm.call.candidates'; - static const String CallHangup = 'm.call.hangup'; - static const String Unknown = 'm.unknown'; - - // To device event types - static const String RoomKey = 'm.room_key'; - static const String ForwardedRoomKey = 'm.forwarded_room_key'; - static const String RoomKeyRequest = 'm.room_key_request'; - static const String KeyVerificationRequest = 'm.key.verification.request'; - static const String KeyVerificationStart = 'm.key.verification.start'; - static const String KeyVerificationDone = 'm.key.verification.done'; - static const String KeyVerificationCancel = 'm.key.verification.cancel'; - static const String KeyVerificationAccept = 'm.key.verification.accept'; - static const String SecretRequest = 'm.secret.request'; - static const String SecretSend = 'm.secret.send'; - static const String CrossSigningSelfSigning = 'm.cross_signing.self_signing'; - static const String CrossSigningUserSigning = 'm.cross_signing.user_signing'; - 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'; -} diff --git a/lib/matrix_api/model/events/secret_storage_default_key_content.dart b/lib/matrix_api/model/events/secret_storage_default_key_content.dart deleted file mode 100644 index b7c561f6..00000000 --- a/lib/matrix_api/model/events/secret_storage_default_key_content.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:famedlysdk/matrix_api/model/basic_event.dart'; -import '../../utils/try_get_map_extension.dart'; - -extension SecretStorageDefaultKeyContentBasicEventExtension on BasicEvent { - SecretStorageDefaultKeyContent get parsedSecretStorageDefaultKeyContent => - SecretStorageDefaultKeyContent.fromJson(content); -} - -class SecretStorageDefaultKeyContent { - String key; - - SecretStorageDefaultKeyContent(); - - SecretStorageDefaultKeyContent.fromJson(Map json) - : key = json.tryGet('key'); - - Map toJson() { - final data = {}; - if (key != null) data['key'] = key; - return data; - } -} diff --git a/lib/matrix_api/model/events/secret_storage_key_content.dart b/lib/matrix_api/model/events/secret_storage_key_content.dart deleted file mode 100644 index 0af9532f..00000000 --- a/lib/matrix_api/model/events/secret_storage_key_content.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:famedlysdk/matrix_api/model/basic_event.dart'; -import '../../utils/try_get_map_extension.dart'; - -extension SecretStorageKeyContentBasicEventExtension on BasicEvent { - SecretStorageKeyContent get parsedSecretStorageKeyContent => - SecretStorageKeyContent.fromJson(content); -} - -class SecretStorageKeyContent { - PassphraseInfo passphrase; - String iv; - String mac; - String algorithm; - - SecretStorageKeyContent(); - - SecretStorageKeyContent.fromJson(Map json) - : passphrase = json['passphrase'] is Map - ? PassphraseInfo.fromJson(json['passphrase']) - : null, - iv = json.tryGet('iv'), - mac = json.tryGet('mac'), - algorithm = json.tryGet('algorithm'); - - Map toJson() { - final data = {}; - if (passphrase != null) data['passphrase'] = passphrase.toJson(); - if (iv != null) data['iv'] = iv; - if (mac != null) data['mac'] = mac; - if (algorithm != null) data['algorithm'] = algorithm; - return data; - } -} - -class PassphraseInfo { - String algorithm; - String salt; - int iterations; - int bits; - - PassphraseInfo(); - - PassphraseInfo.fromJson(Map json) - : 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; - if (bits != null) data['bits'] = bits; - return data; - } -} diff --git a/lib/matrix_api/model/events/tombstone_content.dart b/lib/matrix_api/model/events/tombstone_content.dart deleted file mode 100644 index a53d9e9e..00000000 --- a/lib/matrix_api/model/events/tombstone_content.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:famedlysdk/matrix_api/model/basic_event.dart'; -import '../../utils/try_get_map_extension.dart'; - -extension TombstoneContentBasicEventExtension on BasicEvent { - TombstoneContent get parsedTombstoneContent => - TombstoneContent.fromJson(content); -} - -class TombstoneContent { - String body; - String replacementRoom; - - TombstoneContent.fromJson(Map json) - : body = json.tryGet('body', ''), - replacementRoom = json.tryGet('replacement_room', ''); - - Map toJson() { - final data = {}; - data['body'] = body; - data['replacement_room'] = replacementRoom; - return data; - } -} diff --git a/lib/matrix_api/model/events_sync_update.dart b/lib/matrix_api/model/events_sync_update.dart deleted file mode 100644 index 46b0fb3f..00000000 --- a/lib/matrix_api/model/events_sync_update.dart +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_event.dart'; - -class EventsSyncUpdate { - String start; - String end; - List chunk; - - EventsSyncUpdate.fromJson(Map json) { - start = json['start']; - end = json['end']; - chunk = json['chunk'] != null - ? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - } - - Map toJson() { - final data = {}; - if (start != null) { - data['start'] = start; - } - if (end != null) { - data['end'] = end; - } - if (chunk != null) { - data['chunk'] = chunk.map((i) => i.toJson()).toList(); - } - return data; - } -} diff --git a/lib/matrix_api/model/filter.dart b/lib/matrix_api/model/filter.dart deleted file mode 100644 index b1e18a7d..00000000 --- a/lib/matrix_api/model/filter.dart +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -enum EventFormat { client, federation } - -class Filter { - RoomFilter room; - EventFilter presence; - EventFilter accountData; - EventFormat eventFormat; - List eventFields; - - Filter({ - this.room, - this.presence, - this.accountData, - this.eventFormat, - this.eventFields, - }); - - Filter.fromJson(Map json) { - room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null; - presence = json['presence'] != null - ? EventFilter.fromJson(json['presence']) - : null; - accountData = json['account_data'] != null - ? EventFilter.fromJson(json['account_data']) - : null; - eventFormat = json['event_format'] != null - ? EventFormat.values.firstWhere( - (e) => e.toString().split('.').last == json['event_format']) - : null; - eventFields = json['event_fields'] != null - ? json['event_fields'].cast() - : null; - } - - Map toJson() { - final data = {}; - if (room != null) { - data['room'] = room.toJson(); - } - if (presence != null) { - data['presence'] = presence.toJson(); - } - if (eventFormat != null) { - data['event_format'] = eventFormat.toString().split('.').last; - } - if (eventFields != null) { - data['event_fields'] = eventFields; - } - if (accountData != null) { - data['account_data'] = accountData.toJson(); - } - return data; - } -} - -class RoomFilter { - List notRooms; - List rooms; - StateFilter ephemeral; - bool includeLeave; - StateFilter state; - StateFilter timeline; - StateFilter accountData; - - RoomFilter({ - this.notRooms, - this.rooms, - this.ephemeral, - this.includeLeave, - this.state, - this.timeline, - this.accountData, - }); - - RoomFilter.fromJson(Map json) { - notRooms = json['not_rooms']?.cast(); - rooms = json['rooms']?.cast(); - state = json['state'] != null ? StateFilter.fromJson(json['state']) : null; - includeLeave = json['include_leave']; - timeline = json['timeline'] != null - ? StateFilter.fromJson(json['timeline']) - : null; - ephemeral = json['ephemeral'] != null - ? StateFilter.fromJson(json['ephemeral']) - : null; - accountData = json['account_data'] != null - ? StateFilter.fromJson(json['account_data']) - : null; - } - - Map toJson() { - final data = {}; - if (notRooms != null) { - data['not_rooms'] = notRooms; - } - if (rooms != null) { - data['rooms'] = rooms; - } - if (ephemeral != null) { - data['ephemeral'] = ephemeral.toJson(); - } - if (includeLeave != null) { - data['include_leave'] = includeLeave; - } - if (state != null) { - data['state'] = state.toJson(); - } - if (timeline != null) { - data['timeline'] = timeline.toJson(); - } - if (accountData != null) { - data['account_data'] = accountData.toJson(); - } - return data; - } -} - -class EventFilter { - int limit; - List senders; - List types; - List notRooms; - List notSenders; - - EventFilter( - {this.limit, this.senders, this.types, this.notRooms, this.notSenders}); - - EventFilter.fromJson(Map json) { - limit = json['limit']; - types = json['senders']?.cast(); - types = json['types']?.cast(); - notRooms = json['not_rooms']?.cast(); - notSenders = json['not_senders']?.cast(); - } - - Map toJson() { - final data = {}; - if (limit != null) data['limit'] = limit; - if (types != null) data['types'] = types; - if (notRooms != null) data['not_rooms'] = notRooms; - if (notSenders != null) data['not_senders'] = notSenders; - return data; - } -} - -class StateFilter extends EventFilter { - List notTypes; - bool lazyLoadMembers; - bool includeRedundantMembers; - bool containsUrl; - - StateFilter({ - this.notTypes, - this.lazyLoadMembers, - this.includeRedundantMembers, - this.containsUrl, - int limit, - List senders, - List types, - List notRooms, - List notSenders, - }) : super( - limit: limit, - senders: senders, - types: types, - notRooms: notRooms, - notSenders: notSenders, - ); - - StateFilter.fromJson(Map json) { - final eventFilter = EventFilter.fromJson(json); - limit = eventFilter.limit; - senders = eventFilter.senders; - types = eventFilter.types; - notRooms = eventFilter.notRooms; - notSenders = eventFilter.notSenders; - - notTypes = json['not_types']?.cast(); - lazyLoadMembers = json['lazy_load_members']; - includeRedundantMembers = json['include_redundant_members']; - containsUrl = json['contains_url']; - } - - @override - Map toJson() { - final data = super.toJson(); - if (limit != null) { - data['limit'] = limit; - } - if (notTypes != null) { - data['not_types'] = notTypes; - } - if (lazyLoadMembers != null) { - data['lazy_load_members'] = notTypes; - } - if (includeRedundantMembers != null) { - data['include_redundant_members'] = notTypes; - } - if (containsUrl != null) { - data['contains_url'] = notTypes; - } - return data; - } -} diff --git a/lib/matrix_api/model/keys_query_response.dart b/lib/matrix_api/model/keys_query_response.dart deleted file mode 100644 index ed02e87d..00000000 --- a/lib/matrix_api/model/keys_query_response.dart +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_keys.dart'; -import '../utils/map_copy_extension.dart'; - -class KeysQueryResponse { - Map failures; - Map> deviceKeys; - Map masterKeys; - Map selfSigningKeys; - Map userSigningKeys; - - KeysQueryResponse.fromJson(Map json) { - failures = (json['failures'] as Map)?.copy(); - deviceKeys = json['device_keys'] != null - ? (json['device_keys'] as Map).map( - (k, v) => MapEntry( - k, - (v as Map).map( - (k, v) => MapEntry( - k, - MatrixDeviceKeys.fromJson(v), - ), - ), - ), - ) - : null; - masterKeys = json['master_keys'] != null - ? (json['master_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - - selfSigningKeys = json['self_signing_keys'] != null - ? (json['self_signing_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - - userSigningKeys = json['user_signing_keys'] != null - ? (json['user_signing_keys'] as Map).map( - (k, v) => MapEntry( - k, - MatrixCrossSigningKey.fromJson(v), - ), - ) - : null; - } - - Map toJson() { - final data = {}; - if (failures != null) { - data['failures'] = failures; - } - if (deviceKeys != null) { - data['device_keys'] = deviceKeys.map( - (k, v) => MapEntry( - k, - v.map( - (k, v) => MapEntry( - k, - v.toJson(), - ), - ), - ), - ); - } - if (masterKeys != null) { - data['master_keys'] = masterKeys.map( - (k, v) => MapEntry( - k, - v.toJson(), - ), - ); - } - if (selfSigningKeys != null) { - data['self_signing_keys'] = selfSigningKeys.map( - (k, v) => MapEntry( - k, - v.toJson(), - ), - ); - } - if (userSigningKeys != null) { - data['user_signing_keys'] = userSigningKeys.map( - (k, v) => MapEntry( - k, - v.toJson(), - ), - ); - } - return data; - } -} diff --git a/lib/matrix_api/model/login_response.dart b/lib/matrix_api/model/login_response.dart deleted file mode 100644 index a29627ad..00000000 --- a/lib/matrix_api/model/login_response.dart +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'well_known_informations.dart'; - -class LoginResponse { - String userId; - String accessToken; - String deviceId; - WellKnownInformations wellKnownInformations; - - LoginResponse.fromJson(Map 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']); - } - } - - Map toJson() { - final data = {}; - 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(); - } - return data; - } -} diff --git a/lib/matrix_api/model/login_types.dart b/lib/matrix_api/model/login_types.dart deleted file mode 100644 index 5cb67d22..00000000 --- a/lib/matrix_api/model/login_types.dart +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class LoginTypes { - List flows; - - LoginTypes.fromJson(Map json) { - if (json['flows'] != null) { - flows = []; - json['flows'].forEach((v) { - flows.add(Flows.fromJson(v)); - }); - } - } - - Map toJson() { - final data = {}; - if (flows != null) { - data['flows'] = flows.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class Flows { - String type; - - Flows.fromJson(Map json) { - type = json['type']; - } - - Map toJson() { - final data = {}; - data['type'] = type; - return data; - } -} diff --git a/lib/matrix_api/model/matrix_connection_exception.dart b/lib/matrix_api/model/matrix_connection_exception.dart deleted file mode 100644 index b45192e0..00000000 --- a/lib/matrix_api/model/matrix_connection_exception.dart +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class MatrixConnectionException implements Exception { - final dynamic original; - final StackTrace stackTrace; - MatrixConnectionException(this.original, this.stackTrace); - - @override - String toString() => original.toString(); -} diff --git a/lib/matrix_api/model/matrix_event.dart b/lib/matrix_api/model/matrix_event.dart deleted file mode 100644 index 83fe7596..00000000 --- a/lib/matrix_api/model/matrix_event.dart +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'stripped_state_event.dart'; -import '../utils/map_copy_extension.dart'; - -class MatrixEvent extends StrippedStateEvent { - String eventId; - String roomId; - DateTime originServerTs; - Map unsigned; - Map prevContent; - String redacts; - - MatrixEvent(); - - MatrixEvent.fromJson(Map json) { - final strippedStateEvent = StrippedStateEvent.fromJson(json); - content = strippedStateEvent.content; - type = strippedStateEvent.type; - senderId = strippedStateEvent.senderId; - stateKey = strippedStateEvent.stateKey; - eventId = json['event_id']; - roomId = json['room_id']; - originServerTs = - DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']); - unsigned = (json['unsigned'] as Map)?.copy(); - prevContent = (json['prev_content'] as Map)?.copy(); - redacts = json['redacts']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['event_id'] = eventId; - data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch; - if (unsigned != null) { - data['unsigned'] = unsigned; - } - if (prevContent != null) { - data['prev_content'] = prevContent; - } - if (roomId != null) { - data['room_id'] = roomId; - } - if (data['state_key'] == null) { - data.remove('state_key'); - } - if (redacts != null) { - data['redacts'] = redacts; - } - return data; - } -} diff --git a/lib/matrix_api/model/matrix_exception.dart b/lib/matrix_api/model/matrix_exception.dart deleted file mode 100644 index fa292c9c..00000000 --- a/lib/matrix_api/model/matrix_exception.dart +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'dart:convert'; - -import 'package:http/http.dart' as http; - -enum MatrixError { - M_UNKNOWN, - M_UNKNOWN_TOKEN, - M_NOT_FOUND, - M_FORBIDDEN, - M_LIMIT_EXCEEDED, - M_USER_IN_USE, - M_THREEPID_IN_USE, - M_THREEPID_DENIED, - M_THREEPID_NOT_FOUND, - M_THREEPID_AUTH_FAILED, - M_TOO_LARGE, - M_MISSING_PARAM, - M_UNSUPPORTED_ROOM_VERSION, - M_UNRECOGNIZED, -} - -/// Represents a special response from the Homeserver for errors. -class MatrixException implements Exception { - final Map raw; - - /// The unique identifier for this error. - String get errcode => - raw['errcode'] ?? - (requireAdditionalAuthentication ? 'M_FORBIDDEN' : 'M_UNKNOWN'); - - /// A human readable error description. - String get errorMessage => - raw['error'] ?? - (requireAdditionalAuthentication - ? 'Require additional authentication' - : 'Unknown error'); - - /// The frozen request which triggered this Error - http.Response response; - - MatrixException(this.response) : raw = json.decode(response.body); - MatrixException.fromJson(Map content) : raw = content; - - @override - String toString() => '$errcode: $errorMessage'; - - /// Returns the [ResponseError]. Is ResponseError.NONE if there wasn't an error. - MatrixError get error => MatrixError.values.firstWhere( - (e) => e.toString() == 'MatrixError.${(raw["errcode"] ?? "")}', - orElse: () => MatrixError.M_UNKNOWN); - - int get retryAfterMs => raw['retry_after_ms']; - - /// This is a session identifier that the client must pass back to the homeserver, if one is provided, - /// in subsequent attempts to authenticate in the same API call. - String get session => raw['session']; - - /// Returns true if the server requires additional authentication. - bool get requireAdditionalAuthentication => response != null - ? response.statusCode == 401 - : authenticationFlows != null; - - /// 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 { - if (!raw.containsKey('flows') || !(raw['flows'] is List)) return null; - var flows = []; - for (Map flow in raw['flows']) { - if (flow['stages'] is List) { - flows.add(AuthenticationFlow(List.from(flow['stages']))); - } - } - return flows; - } - - /// This section contains any information that the client will need to know in order to use a given type - /// of authentication. For each authentication type presented, that type may be present as a key in this - /// dictionary. For example, the public part of an OAuth client ID could be given here. - Map get authenticationParams => raw['params']; - - /// Returns the list of already completed authentication flows from previous requests. - List get completedAuthenticationFlows => - List.from(raw['completed'] ?? []); -} - -/// 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 -class AuthenticationFlow { - final List stages; - const AuthenticationFlow(this.stages); -} diff --git a/lib/matrix_api/model/matrix_keys.dart b/lib/matrix_api/model/matrix_keys.dart deleted file mode 100644 index 317ef390..00000000 --- a/lib/matrix_api/model/matrix_keys.dart +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -class MatrixSignableKey { - String userId; - String identifier; - Map keys; - Map> signatures; - Map unsigned; - - MatrixSignableKey(this.userId, this.identifier, this.keys, this.signatures, - {this.unsigned}); - - // This object is used for signing so we need the raw json too - Map _json; - - MatrixSignableKey.fromJson(Map json) { - _json = json; - userId = json['user_id']; - keys = Map.from(json['keys']); - // we need to manually copy to ensure that our map is Map> - signatures = json['signatures'] is Map - ? Map>.from((json['signatures'] as Map) - .map((k, v) => MapEntry(k, Map.from(v)))) - : null; - unsigned = (json['unsigned'] as Map)?.copy(); - } - - Map toJson() { - final data = _json ?? {}; - data['user_id'] = userId; - data['keys'] = keys; - - if (signatures != null) { - data['signatures'] = signatures; - } - if (unsigned != null) { - data['unsigned'] = unsigned; - } - return data; - } -} - -class MatrixCrossSigningKey extends MatrixSignableKey { - List usage; - String get publicKey => identifier; - - MatrixCrossSigningKey( - String userId, - this.usage, - Map keys, - Map> signatures, { - Map unsigned, - }) : super(userId, keys?.values?.first, keys, signatures, unsigned: unsigned); - - @override - MatrixCrossSigningKey.fromJson(Map json) - : super.fromJson(json) { - usage = List.from(json['usage']); - identifier = keys?.values?.first; - } - - @override - Map toJson() { - final data = super.toJson(); - data['usage'] = usage; - return data; - } -} - -class MatrixDeviceKeys extends MatrixSignableKey { - String get deviceId => identifier; - List algorithms; - String get deviceDisplayName => - unsigned != null ? unsigned['device_display_name'] : null; - - MatrixDeviceKeys( - String userId, - String deviceId, - this.algorithms, - Map keys, - Map> signatures, { - Map unsigned, - }) : super(userId, deviceId, keys, signatures, unsigned: unsigned); - - @override - MatrixDeviceKeys.fromJson(Map json) : super.fromJson(json) { - identifier = json['device_id']; - algorithms = json['algorithms'].cast(); - } - - @override - Map toJson() { - final data = super.toJson(); - data['device_id'] = deviceId; - data['algorithms'] = algorithms; - return data; - } -} diff --git a/lib/matrix_api/model/message_types.dart b/lib/matrix_api/model/message_types.dart deleted file mode 100644 index 90fe2d08..00000000 --- a/lib/matrix_api/model/message_types.dart +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -abstract class MessageTypes { - static const String Text = 'm.text'; - static const String Emote = 'm.emote'; - static const String Notice = 'm.notice'; - static const String Image = 'm.image'; - static const String Video = 'm.video'; - static const String Audio = 'm.audio'; - static const String File = 'm.file'; - static const String Location = 'm.location'; - static const String Sticker = 'm.sticker'; - static const String BadEncrypted = 'm.bad.encrypted'; - static const String None = 'm.none'; -} diff --git a/lib/matrix_api/model/notifications_query_response.dart b/lib/matrix_api/model/notifications_query_response.dart deleted file mode 100644 index f9eff6b9..00000000 --- a/lib/matrix_api/model/notifications_query_response.dart +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_event.dart'; - -class NotificationsQueryResponse { - String nextToken; - List notifications; - - NotificationsQueryResponse.fromJson(Map json) { - nextToken = json['next_token']; - notifications = []; - json['notifications'].forEach((v) { - notifications.add(Notification.fromJson(v)); - }); - } - - Map toJson() { - final data = {}; - if (nextToken != null) { - data['next_token'] = nextToken; - } - data['notifications'] = notifications.map((v) => v.toJson()).toList(); - return data; - } -} - -class Notification { - List actions; - String profileTag; - bool read; - String roomId; - int ts; - MatrixEvent event; - - Notification.fromJson(Map json) { - actions = json['actions'].cast(); - profileTag = json['profile_tag']; - read = json['read']; - roomId = json['room_id']; - ts = json['ts']; - event = MatrixEvent.fromJson(json['event']); - } - - Map toJson() { - final data = {}; - data['actions'] = actions; - if (profileTag != null) { - data['profile_tag'] = profileTag; - } - data['read'] = read; - data['room_id'] = roomId; - data['ts'] = ts; - data['event'] = event.toJson(); - return data; - } -} diff --git a/lib/matrix_api/model/one_time_keys_claim_response.dart b/lib/matrix_api/model/one_time_keys_claim_response.dart deleted file mode 100644 index 7607892b..00000000 --- a/lib/matrix_api/model/one_time_keys_claim_response.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -class OneTimeKeysClaimResponse { - Map failures; - Map> oneTimeKeys; - - OneTimeKeysClaimResponse.fromJson(Map json) { - failures = (json['failures'] as Map)?.copy() ?? {}; - // We still need a Map<...>.from(...) to ensure all second-level entries are also maps - oneTimeKeys = Map>.from( - (json['one_time_keys'] as Map).copy()); - } - - Map toJson() { - final data = {}; - if (failures != null) { - data['failures'] = failures; - } - if (oneTimeKeys != null) { - data['one_time_keys'] = oneTimeKeys; - } - return data; - } -} diff --git a/lib/matrix_api/model/open_graph_data.dart b/lib/matrix_api/model/open_graph_data.dart deleted file mode 100644 index d2d8eb60..00000000 --- a/lib/matrix_api/model/open_graph_data.dart +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class OpenGraphData { - String ogTitle; - String ogDescription; - String ogImage; - String ogImageType; - int ogImageHeight; - int ogImageWidth; - int matrixImageSize; - - OpenGraphData.fromJson(Map json) { - ogTitle = json['og:title']; - ogDescription = json['og:description']; - ogImage = json['og:image']; - ogImageType = json['og:image:type']; - ogImageHeight = json['og:image:height']; - ogImageWidth = json['og:image:width']; - matrixImageSize = json['matrix:image:size']; - } - - Map toJson() { - final data = {}; - if (ogTitle != null) { - data['og:title'] = ogTitle; - } - if (ogDescription != null) { - data['og:description'] = ogDescription; - } - if (ogImage != null) { - data['og:image'] = ogImage; - } - if (ogImageType != null) { - data['og:image:type'] = ogImageType; - } - if (ogImageHeight != null) { - data['og:image:height'] = ogImageHeight; - } - if (ogImageWidth != null) { - data['og:image:width'] = ogImageWidth; - } - if (matrixImageSize != null) { - data['matrix:image:size'] = matrixImageSize; - } - return data; - } -} diff --git a/lib/matrix_api/model/open_id_credentials.dart b/lib/matrix_api/model/open_id_credentials.dart deleted file mode 100644 index 1d2902bd..00000000 --- a/lib/matrix_api/model/open_id_credentials.dart +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class OpenIdCredentials { - String accessToken; - String tokenType; - String matrixServerName; - double expiresIn; - - OpenIdCredentials.fromJson(Map json) { - accessToken = json['access_token']; - tokenType = json['token_type']; - matrixServerName = json['matrix_server_name']; - expiresIn = json['expires_in']; - } - - Map toJson() { - final data = {}; - data['access_token'] = accessToken; - data['token_type'] = tokenType; - data['matrix_server_name'] = matrixServerName; - data['expires_in'] = expiresIn; - return data; - } -} diff --git a/lib/matrix_api/model/presence.dart b/lib/matrix_api/model/presence.dart deleted file mode 100644 index c8044063..00000000 --- a/lib/matrix_api/model/presence.dart +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'basic_event_with_sender.dart'; -import 'presence_content.dart'; - -class Presence extends BasicEventWithSender { - PresenceContent presence; - - Presence.fromJson(Map json) { - final basicEvent = BasicEventWithSender.fromJson(json); - type = basicEvent.type; - content = basicEvent.content; - senderId = basicEvent.senderId; - presence = PresenceContent.fromJson(content); - } -} diff --git a/lib/matrix_api/model/presence_content.dart b/lib/matrix_api/model/presence_content.dart deleted file mode 100644 index df9d2f08..00000000 --- a/lib/matrix_api/model/presence_content.dart +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -enum PresenceType { online, offline, unavailable } - -class PresenceContent { - PresenceType presence; - int lastActiveAgo; - String statusMsg; - bool currentlyActive; - - PresenceContent.fromJson(Map json) { - presence = PresenceType.values - .firstWhere((p) => p.toString().split('.').last == json['presence']); - lastActiveAgo = json['last_active_ago']; - statusMsg = json['status_msg']; - currentlyActive = json['currently_active']; - } - - Map toJson() { - final data = {}; - data['presence'] = presence.toString().split('.').last; - if (lastActiveAgo != null) { - data['last_active_ago'] = lastActiveAgo; - } - if (statusMsg != null) { - data['status_msg'] = statusMsg; - } - if (currentlyActive != null) { - data['currently_active'] = currentlyActive; - } - return data; - } -} diff --git a/lib/matrix_api/model/profile.dart b/lib/matrix_api/model/profile.dart deleted file mode 100644 index 37eace57..00000000 --- a/lib/matrix_api/model/profile.dart +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class Profile { - /// The user's avatar URL if they have set one, otherwise null. - Uri avatarUrl; - - /// The user's display name if they have set one, otherwise null. - String displayname; - - /// The matrix ID of this user. May be omitted. - String userId; - - Map additionalContent; - - Profile(this.displayname, this.avatarUrl, - {this.additionalContent = const {}}); - - Profile.fromJson(Map json) - : avatarUrl = - json['avatar_url'] != null ? Uri.parse(json['avatar_url']) : null, - displayname = json['display_name'] ?? json['displayname'], - userId = json['user_id'], - additionalContent = json; - - Map toJson() { - return additionalContent; - } -} diff --git a/lib/matrix_api/model/public_rooms_response.dart b/lib/matrix_api/model/public_rooms_response.dart deleted file mode 100644 index f227dfb7..00000000 --- a/lib/matrix_api/model/public_rooms_response.dart +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class PublicRoomsResponse { - List chunk; - String nextBatch; - String prevBatch; - int totalRoomCountEstimate; - - PublicRoomsResponse.fromJson(Map json) { - chunk = []; - json['chunk'].forEach((v) { - chunk.add(PublicRoom.fromJson(v)); - }); - nextBatch = json['next_batch']; - prevBatch = json['prev_batch']; - totalRoomCountEstimate = json['total_room_count_estimate']; - } - - Map toJson() { - final data = {}; - data['chunk'] = chunk.map((v) => v.toJson()).toList(); - if (nextBatch != null) { - data['next_batch'] = nextBatch; - } - if (prevBatch != null) { - data['prev_batch'] = prevBatch; - } - if (totalRoomCountEstimate != null) { - data['total_room_count_estimate'] = totalRoomCountEstimate; - } - return data; - } -} - -class PublicRoom { - List aliases; - String avatarUrl; - bool guestCanJoin; - String name; - int numJoinedMembers; - String roomId; - String topic; - bool worldReadable; - String canonicalAlias; - - PublicRoom.fromJson(Map json) { - aliases = json['aliases']?.cast(); - avatarUrl = json['avatar_url']; - guestCanJoin = json['guest_can_join']; - canonicalAlias = json['canonical_alias']; - name = json['name']; - numJoinedMembers = json['num_joined_members']; - roomId = json['room_id']; - topic = json['topic']; - worldReadable = json['world_readable']; - } - - Map toJson() { - final data = {}; - if (aliases != null) { - data['aliases'] = aliases; - } - if (canonicalAlias != null) { - data['canonical_alias'] = canonicalAlias; - } - if (avatarUrl != null) { - data['avatar_url'] = avatarUrl; - } - data['guest_can_join'] = guestCanJoin; - if (name != null) { - data['name'] = name; - } - data['num_joined_members'] = numJoinedMembers; - data['room_id'] = roomId; - if (topic != null) { - data['topic'] = topic; - } - data['world_readable'] = worldReadable; - return data; - } -} diff --git a/lib/matrix_api/model/push_rule_set.dart b/lib/matrix_api/model/push_rule_set.dart deleted file mode 100644 index 2c9682b5..00000000 --- a/lib/matrix_api/model/push_rule_set.dart +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -enum PushRuleKind { content, override, room, sender, underride } -enum PushRuleAction { notify, dont_notify, coalesce, set_tweak } - -class PushRuleSet { - List content; - List override; - List room; - List sender; - List underride; - - PushRuleSet.fromJson(Map json) { - if (json['content'] != null) { - content = - (json['content'] as List).map((i) => PushRule.fromJson(i)).toList(); - } - if (json['override'] != null) { - override = - (json['override'] as List).map((i) => PushRule.fromJson(i)).toList(); - } - if (json['room'] != null) { - room = (json['room'] as List).map((i) => PushRule.fromJson(i)).toList(); - } - if (json['sender'] != null) { - sender = - (json['sender'] as List).map((i) => PushRule.fromJson(i)).toList(); - } - if (json['underride'] != null) { - underride = - (json['underride'] as List).map((i) => PushRule.fromJson(i)).toList(); - } - } - - Map toJson() { - final data = {}; - if (content != null) { - data['content'] = content.map((v) => v.toJson()).toList(); - } - if (override != null) { - data['override'] = override.map((v) => v.toJson()).toList(); - } - if (room != null) { - data['room'] = room.map((v) => v.toJson()).toList(); - } - if (sender != null) { - data['sender'] = sender.map((v) => v.toJson()).toList(); - } - if (underride != null) { - data['underride'] = underride.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class PushRule { - List actions; - List conditions; - bool isDefault; - bool enabled; - String pattern; - String ruleId; - - PushRule.fromJson(Map json) { - actions = json['actions']; - isDefault = json['default']; - enabled = json['enabled']; - pattern = json['pattern']; - ruleId = json['rule_id']; - conditions = json['conditions'] != null - ? (json['conditions'] as List) - .map((i) => PushConditions.fromJson(i)) - .toList() - : null; - } - - Map toJson() { - final data = {}; - data['actions'] = actions; - data['default'] = isDefault; - data['enabled'] = enabled; - if (pattern != null) { - data['pattern'] = pattern; - } - if (conditions != null) { - data['conditions'] = conditions.map((i) => i.toJson()).toList(); - } - data['rule_id'] = ruleId; - return data; - } -} - -class PushConditions { - String key; - String kind; - String pattern; - String isOperator; - - PushConditions( - this.kind, { - this.key, - this.pattern, - this.isOperator, - }); - - PushConditions.fromJson(Map json) { - key = json['key']; - kind = json['kind']; - pattern = json['pattern']; - isOperator = json['is']; - } - - Map toJson() { - final data = {}; - if (key != null) { - data['key'] = key; - } - data['kind'] = kind; - if (pattern != null) { - data['pattern'] = pattern; - } - if (isOperator != null) { - data['is'] = isOperator; - } - return data; - } -} diff --git a/lib/matrix_api/model/pusher.dart b/lib/matrix_api/model/pusher.dart deleted file mode 100644 index 00bc2803..00000000 --- a/lib/matrix_api/model/pusher.dart +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class Pusher { - String pushkey; - String kind; - String appId; - String appDisplayName; - String deviceDisplayName; - String profileTag; - String lang; - PusherData data; - - Pusher( - this.pushkey, - this.appId, - this.appDisplayName, - this.deviceDisplayName, - this.lang, - this.data, { - this.profileTag, - this.kind, - }); - - Pusher.fromJson(Map json) { - pushkey = json['pushkey']; - kind = json['kind']; - appId = json['app_id']; - appDisplayName = json['app_display_name']; - deviceDisplayName = json['device_display_name']; - profileTag = json['profile_tag']; - lang = json['lang']; - data = PusherData.fromJson(json['data']); - } - - Map toJson() { - final data = {}; - data['pushkey'] = pushkey; - data['kind'] = kind; - data['app_id'] = appId; - data['app_display_name'] = appDisplayName; - data['device_display_name'] = deviceDisplayName; - if (profileTag != null) { - data['profile_tag'] = profileTag; - } - data['lang'] = lang; - data['data'] = this.data.toJson(); - return data; - } -} - -class PusherData { - Uri url; - String format; - - PusherData({ - this.url, - this.format, - }); - - PusherData.fromJson(Map json) { - if (json.containsKey('url')) { - url = Uri.parse(json['url']); - } - format = json['format']; - } - - Map toJson() { - final data = {}; - if (url != null) { - data['url'] = url.toString(); - } - if (format != null) { - data['format'] = format; - } - return data; - } -} diff --git a/lib/matrix_api/model/request_token_response.dart b/lib/matrix_api/model/request_token_response.dart deleted file mode 100644 index ee264be6..00000000 --- a/lib/matrix_api/model/request_token_response.dart +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class RequestTokenResponse { - String sid; - String submitUrl; - - RequestTokenResponse.fromJson(Map json) { - sid = json['sid']; - submitUrl = json['submit_url']; - } - - Map toJson() { - final data = {}; - data['sid'] = sid; - data['submit_url'] = submitUrl; - return data; - } -} diff --git a/lib/matrix_api/model/room_alias_informations.dart b/lib/matrix_api/model/room_alias_informations.dart deleted file mode 100644 index d6b81640..00000000 --- a/lib/matrix_api/model/room_alias_informations.dart +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class RoomAliasInformations { - String roomId; - List servers; - - RoomAliasInformations.fromJson(Map json) { - roomId = json['room_id']; - servers = json['servers'].cast(); - } - - Map toJson() { - final data = {}; - data['room_id'] = roomId; - data['servers'] = servers; - return data; - } -} diff --git a/lib/matrix_api/model/room_keys_info.dart b/lib/matrix_api/model/room_keys_info.dart deleted file mode 100644 index 3f55f8cc..00000000 --- a/lib/matrix_api/model/room_keys_info.dart +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../../matrix_api.dart'; - -enum RoomKeysAlgorithmType { v1Curve25519AesSha2 } - -extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType { - String get algorithmString { - switch (this) { - case RoomKeysAlgorithmType.v1Curve25519AesSha2: - return AlgorithmTypes.megolmBackupV1Curve25519AesSha2; - default: - return null; - } - } - - static RoomKeysAlgorithmType fromAlgorithmString(String s) { - switch (s) { - case AlgorithmTypes.megolmBackupV1Curve25519AesSha2: - return RoomKeysAlgorithmType.v1Curve25519AesSha2; - default: - return null; - } - } -} - -class RoomKeysVersionResponse { - RoomKeysAlgorithmType algorithm; - Map authData; - int count; - String etag; - String version; - - RoomKeysVersionResponse.fromJson(Map json) { - algorithm = - RoomKeysAlgorithmTypeExtension.fromAlgorithmString(json['algorithm']); - authData = json['auth_data']; - count = json['count']; - etag = - json['etag'].toString(); // synapse replies an int but docs say string? - version = json['version']; - } - - Map toJson() { - final data = {}; - data['algorithm'] = algorithm?.algorithmString; - data['auth_data'] = authData; - data['count'] = count; - data['etag'] = etag; - data['version'] = version; - return data; - } -} diff --git a/lib/matrix_api/model/room_keys_keys.dart b/lib/matrix_api/model/room_keys_keys.dart deleted file mode 100644 index 69870665..00000000 --- a/lib/matrix_api/model/room_keys_keys.dart +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class RoomKeysSingleKey { - int firstMessageIndex; - int forwardedCount; - bool isVerified; - Map sessionData; - - RoomKeysSingleKey( - {this.firstMessageIndex, - this.forwardedCount, - this.isVerified, - this.sessionData}); - - RoomKeysSingleKey.fromJson(Map json) { - firstMessageIndex = json['first_message_index']; - forwardedCount = json['forwarded_count']; - isVerified = json['is_verified']; - sessionData = json['session_data']; - } - - Map toJson() { - final data = {}; - data['first_message_index'] = firstMessageIndex; - data['forwarded_count'] = forwardedCount; - data['is_verified'] = isVerified; - data['session_data'] = sessionData; - return data; - } -} - -class RoomKeysRoom { - Map sessions; - - RoomKeysRoom({this.sessions}) { - sessions ??= {}; - } - - RoomKeysRoom.fromJson(Map json) { - sessions = (json['sessions'] as Map) - .map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v))); - } - - Map toJson() { - final data = {}; - data['sessions'] = sessions.map((k, v) => MapEntry(k, v.toJson())); - return data; - } -} - -class RoomKeys { - Map rooms; - - RoomKeys({this.rooms}) { - rooms ??= {}; - } - - RoomKeys.fromJson(Map json) { - rooms = (json['rooms'] as Map) - .map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v))); - } - - Map toJson() { - final data = {}; - data['rooms'] = rooms.map((k, v) => MapEntry(k, v.toJson())); - return data; - } -} - -class RoomKeysUpdateResponse { - String etag; - int count; - - RoomKeysUpdateResponse.fromJson(Map json) { - etag = json['etag']; // synapse replies an int but docs say string? - count = json['count']; - } - - Map toJson() { - final data = {}; - data['etag'] = etag; - data['count'] = count; - return data; - } -} diff --git a/lib/matrix_api/model/room_summary.dart b/lib/matrix_api/model/room_summary.dart deleted file mode 100644 index 67b6a8f3..00000000 --- a/lib/matrix_api/model/room_summary.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class RoomSummary { - List mHeroes; - int mJoinedMemberCount; - int mInvitedMemberCount; - RoomSummary.fromJson(Map json) { - mHeroes = - json['m.heroes'] != null ? List.from(json['m.heroes']) : null; - mJoinedMemberCount = json['m.joined_member_count']; - mInvitedMemberCount = json['m.invited_member_count']; - } - Map toJson() { - final data = {}; - if (mHeroes != null) { - data['m.heroes'] = mHeroes; - } - if (mJoinedMemberCount != null) { - data['m.joined_member_count'] = mJoinedMemberCount; - } - if (mInvitedMemberCount != null) { - data['m.invited_member_count'] = mInvitedMemberCount; - } - return data; - } -} diff --git a/lib/matrix_api/model/server_capabilities.dart b/lib/matrix_api/model/server_capabilities.dart deleted file mode 100644 index 0ae7c1ee..00000000 --- a/lib/matrix_api/model/server_capabilities.dart +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -enum RoomVersionStability { stable, unstable } - -class ServerCapabilities { - MChangePassword mChangePassword; - MRoomVersions mRoomVersions; - Map customCapabilities; - - ServerCapabilities.fromJson(Map json) { - mChangePassword = json['m.change_password'] != null - ? MChangePassword.fromJson(json['m.change_password']) - : null; - mRoomVersions = json['m.room_versions'] != null - ? MRoomVersions.fromJson(json['m.room_versions']) - : null; - customCapabilities = json.copy(); - customCapabilities.remove('m.change_password'); - customCapabilities.remove('m.room_versions'); - } - - Map toJson() { - final data = {}; - if (mChangePassword != null) { - data['m.change_password'] = mChangePassword.toJson(); - } - if (mRoomVersions != null) { - data['m.room_versions'] = mRoomVersions.toJson(); - } - for (final entry in customCapabilities.entries) { - data[entry.key] = entry.value; - } - return data; - } -} - -class MChangePassword { - bool enabled; - - MChangePassword.fromJson(Map json) { - enabled = json['enabled']; - } - - Map toJson() { - final data = {}; - data['enabled'] = enabled; - return data; - } -} - -class MRoomVersions { - String defaultVersion; - Map available; - - MRoomVersions.fromJson(Map json) { - defaultVersion = json['default']; - available = (json['available'] as Map).map( - (k, v) => MapEntry( - k, - RoomVersionStability.values - .firstWhere((r) => r.toString().split('.').last == v), - ), - ); - } - - Map toJson() { - final data = {}; - data['default'] = defaultVersion; - data['available'] = available.map( - (k, v) => MapEntry(k, v.toString().split('.').last)); - return data; - } -} diff --git a/lib/matrix_api/model/stripped_state_event.dart b/lib/matrix_api/model/stripped_state_event.dart deleted file mode 100644 index 29c0740a..00000000 --- a/lib/matrix_api/model/stripped_state_event.dart +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'basic_event_with_sender.dart'; - -class StrippedStateEvent extends BasicEventWithSender { - String stateKey; - - StrippedStateEvent(); - StrippedStateEvent.fromJson(Map json) { - final basicEvent = BasicEventWithSender.fromJson(json); - content = basicEvent.content; - type = basicEvent.type; - senderId = basicEvent.senderId; - stateKey = json['state_key']; - } - - @override - Map toJson() { - final data = super.toJson(); - data['state_key'] = stateKey; - return data; - } -} diff --git a/lib/matrix_api/model/supported_protocol.dart b/lib/matrix_api/model/supported_protocol.dart deleted file mode 100644 index 736b7d6d..00000000 --- a/lib/matrix_api/model/supported_protocol.dart +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class SupportedProtocol { - List userFields; - List locationFields; - String icon; - Map fieldTypes; - List instances; - - SupportedProtocol.fromJson(Map json) { - userFields = json['user_fields'].cast(); - locationFields = json['location_fields'].cast(); - icon = json['icon']; - fieldTypes = (json['field_types'] as Map) - .map((k, v) => MapEntry(k, ProtocolFieldType.fromJson(v))); - instances = []; - json['instances'].forEach((v) { - instances.add(ProtocolInstance.fromJson(v)); - }); - } - - Map toJson() { - final data = {}; - data['user_fields'] = userFields; - 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; - } -} - -class ProtocolFieldType { - String regexp; - String placeholder; - - ProtocolFieldType.fromJson(Map json) { - regexp = json['regexp']; - placeholder = json['placeholder']; - } - - Map toJson() { - final data = {}; - data['regexp'] = regexp; - data['placeholder'] = placeholder; - return data; - } -} - -class ProtocolInstance { - String networkId; - String desc; - String icon; - dynamic fields; - - ProtocolInstance.fromJson(Map json) { - networkId = json['network_id']; - desc = json['desc']; - icon = json['icon']; - fields = json['fields']; - } - - Map toJson() { - final data = {}; - data['network_id'] = networkId; - data['desc'] = desc; - if (icon != null) { - data['icon'] = icon; - } - data['fields'] = fields; - - return data; - } -} diff --git a/lib/matrix_api/model/supported_versions.dart b/lib/matrix_api/model/supported_versions.dart deleted file mode 100644 index 33ab8c49..00000000 --- a/lib/matrix_api/model/supported_versions.dart +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class SupportedVersions { - List versions; - Map unstableFeatures; - - SupportedVersions.fromJson(Map json) { - versions = json['versions'].cast(); - unstableFeatures = Map.from(json['unstable_features'] ?? {}); - } - - Map toJson() { - final data = {}; - data['versions'] = versions; - if (unstableFeatures != null) { - data['unstable_features'] = unstableFeatures; - } - return data; - } -} diff --git a/lib/matrix_api/model/sync_update.dart b/lib/matrix_api/model/sync_update.dart deleted file mode 100644 index c36c09e1..00000000 --- a/lib/matrix_api/model/sync_update.dart +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'basic_event.dart'; -import 'basic_event_with_sender.dart'; -import 'basic_room_event.dart'; -import 'matrix_event.dart'; -import 'presence.dart'; -import 'room_summary.dart'; -import 'stripped_state_event.dart'; - -class SyncUpdate { - String nextBatch; - RoomsUpdate rooms; - List presence; - List accountData; - List toDevice; - DeviceListsUpdate deviceLists; - Map deviceOneTimeKeysCount; - - SyncUpdate(); - - SyncUpdate.fromJson(Map json) { - nextBatch = json['next_batch']; - rooms = json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null; - presence = (json['presence'] != null && json['presence']['events'] != null) - ? (json['presence']['events'] as List) - .map((i) => Presence.fromJson(i)) - .toList() - : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicEvent.fromJson(i)) - .toList() - : null; - toDevice = - (json['to_device'] != null && json['to_device']['events'] != null) - ? (json['to_device']['events'] as List) - .map((i) => BasicEventWithSender.fromJson(i)) - .toList() - : null; - deviceLists = json['device_lists'] != null - ? DeviceListsUpdate.fromJson(json['device_lists']) - : null; - deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null - ? Map.from(json['device_one_time_keys_count']) - : null; - } - - Map toJson() { - final data = {}; - data['next_batch'] = nextBatch; - if (rooms != null) { - data['rooms'] = rooms.toJson(); - } - if (presence != null) { - data['presence'] = { - 'events': presence.map((i) => i.toJson()).toList(), - }; - } - if (accountData != null) { - data['account_data'] = { - 'events': accountData.map((i) => i.toJson()).toList(), - }; - } - if (toDevice != null) { - data['to_device'] = { - 'events': toDevice.map((i) => i.toJson()).toList(), - }; - } - if (deviceLists != null) { - data['device_lists'] = deviceLists.toJson(); - } - if (deviceOneTimeKeysCount != null) { - data['device_one_time_keys_count'] = deviceOneTimeKeysCount; - } - return data; - } -} - -class RoomsUpdate { - Map join; - Map invite; - Map leave; - - RoomsUpdate(); - - RoomsUpdate.fromJson(Map json) { - join = json['join'] != null - ? (json['join'] as Map) - .map((k, v) => MapEntry(k, JoinedRoomUpdate.fromJson(v))) - : null; - invite = json['invite'] != null - ? (json['invite'] as Map) - .map((k, v) => MapEntry(k, InvitedRoomUpdate.fromJson(v))) - : null; - leave = json['leave'] != null - ? (json['leave'] as Map) - .map((k, v) => MapEntry(k, LeftRoomUpdate.fromJson(v))) - : null; - } - Map toJson() { - final data = {}; - if (join != null) { - data['join'] = join.map((k, v) => MapEntry(k, v.toJson())); - } - if (invite != null) { - data['invite'] = invite.map((k, v) => MapEntry(k, v.toJson())); - } - if (leave != null) { - data['leave'] = leave.map((k, v) => MapEntry(k, v.toJson())); - } - return data; - } -} - -abstract class SyncRoomUpdate {} - -class JoinedRoomUpdate extends SyncRoomUpdate { - RoomSummary summary; - List state; - TimelineUpdate timeline; - List ephemeral; - List accountData; - UnreadNotificationCounts unreadNotifications; - - JoinedRoomUpdate(); - - JoinedRoomUpdate.fromJson(Map json) { - summary = - json['summary'] != null ? RoomSummary.fromJson(json['summary']) : null; - state = (json['state'] != null && json['state']['events'] != null) - ? (json['state']['events'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList() - : null; - timeline = json['timeline'] != null - ? TimelineUpdate.fromJson(json['timeline']) - : null; - - ephemeral = - (json['ephemeral'] != null && json['ephemeral']['events'] != null) - ? (json['ephemeral']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() - : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() - : null; - unreadNotifications = json['unread_notifications'] != null - ? UnreadNotificationCounts.fromJson(json['unread_notifications']) - : null; - } - - Map toJson() { - final data = {}; - if (summary != null) { - data['summary'] = summary.toJson(); - } - if (state != null) { - data['state'] = { - 'events': state.map((i) => i.toJson()).toList(), - }; - } - if (timeline != null) { - data['timeline'] = timeline.toJson(); - } - if (ephemeral != null) { - data['ephemeral'] = { - 'events': ephemeral.map((i) => i.toJson()).toList(), - }; - } - if (accountData != null) { - data['account_data'] = { - 'events': accountData.map((i) => i.toJson()).toList(), - }; - } - if (unreadNotifications != null) { - data['unread_notifications'] = unreadNotifications.toJson(); - } - return data; - } -} - -class InvitedRoomUpdate extends SyncRoomUpdate { - List inviteState; - InvitedRoomUpdate.fromJson(Map json) { - inviteState = - (json['invite_state'] != null && json['invite_state']['events'] != null) - ? (json['invite_state']['events'] as List) - .map((i) => StrippedStateEvent.fromJson(i)) - .toList() - : null; - } - Map toJson() { - final data = {}; - if (inviteState != null) { - data['invite_state'] = { - 'events': inviteState.map((i) => i.toJson()).toList(), - }; - } - return data; - } -} - -class LeftRoomUpdate extends SyncRoomUpdate { - List state; - TimelineUpdate timeline; - List accountData; - - LeftRoomUpdate(); - - LeftRoomUpdate.fromJson(Map json) { - state = (json['state'] != null && json['state']['events'] != null) - ? (json['state']['events'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList() - : null; - timeline = json['timeline'] != null - ? TimelineUpdate.fromJson(json['timeline']) - : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() - : null; - } - Map toJson() { - final data = {}; - if (state != null) { - data['state'] = { - 'events': state.map((i) => i.toJson()).toList(), - }; - } - if (timeline != null) { - data['timeline'] = timeline.toJson(); - } - if (accountData != null) { - data['account_data'] = { - 'events': accountData.map((i) => i.toJson()).toList(), - }; - } - return data; - } -} - -class TimelineUpdate { - List events; - bool limited; - String prevBatch; - - TimelineUpdate(); - - TimelineUpdate.fromJson(Map json) { - events = json['events'] != null - ? (json['events'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - limited = json['limited']; - prevBatch = json['prev_batch']; - } - - Map toJson() { - final data = {}; - if (events != null) { - data['events'] = events.map((i) => i.toJson()).toList(); - } - if (limited != null) { - data['limited'] = limited; - } - if (prevBatch != null) { - data['prev_batch'] = prevBatch; - } - return data; - } -} - -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) { - data['highlight_count'] = highlightCount; - } - if (notificationCount != null) { - data['notification_count'] = notificationCount; - } - return data; - } -} - -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) { - data['changed'] = changed; - } - if (left != null) { - data['left'] = left; - } - return data; - } -} diff --git a/lib/matrix_api/model/tag.dart b/lib/matrix_api/model/tag.dart deleted file mode 100644 index f63d6e57..00000000 --- a/lib/matrix_api/model/tag.dart +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class Tag { - double order; - - Tag.fromJson(Map json) { - order = double.tryParse(json['order'].toString()); - } - - Map toJson() { - final data = {}; - if (order != null) { - data['order'] = order; - } - return data; - } -} - -abstract class TagType { - static const String Favourite = 'm.favourite'; - static const String LowPriority = 'm.lowpriority'; - static const String ServerNotice = 'm.server_notice'; - static bool isValid(String tag) => tag.startsWith('m.') - ? [Favourite, LowPriority, ServerNotice].contains(tag) - : true; -} diff --git a/lib/matrix_api/model/third_party_identifier.dart b/lib/matrix_api/model/third_party_identifier.dart deleted file mode 100644 index 50628fff..00000000 --- a/lib/matrix_api/model/third_party_identifier.dart +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'package:famedlysdk/matrix_api.dart'; - -class ThirdPartyIdentifier { - ThirdPartyIdentifierMedium medium; - String address; - int validatedAt; - int addedAt; - - ThirdPartyIdentifier.fromJson(Map json) { - medium = ThirdPartyIdentifierMedium.values - .firstWhere((medium) => describeEnum(medium) == json['medium']); - address = json['address']; - validatedAt = json['validated_at']; - addedAt = json['added_at']; - } - - Map toJson() { - final data = {}; - data['medium'] = describeEnum(medium); - data['address'] = address; - data['validated_at'] = validatedAt; - data['added_at'] = addedAt; - return data; - } -} diff --git a/lib/matrix_api/model/third_party_location.dart b/lib/matrix_api/model/third_party_location.dart deleted file mode 100644 index 39546099..00000000 --- a/lib/matrix_api/model/third_party_location.dart +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -class ThirdPartyLocation { - String alias; - String protocol; - Map fields; - - ThirdPartyLocation.fromJson(Map json) { - alias = json['alias']; - protocol = json['protocol']; - fields = (json['fields'] as Map).copy(); - } - - Map toJson() { - final data = {}; - data['alias'] = alias; - data['protocol'] = protocol; - data['fields'] = fields; - return data; - } -} diff --git a/lib/matrix_api/model/third_party_user.dart b/lib/matrix_api/model/third_party_user.dart deleted file mode 100644 index e19818e8..00000000 --- a/lib/matrix_api/model/third_party_user.dart +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import '../utils/map_copy_extension.dart'; - -class ThirdPartyUser { - String userId; - String protocol; - Map fields; - - ThirdPartyUser.fromJson(Map json) { - userId = json['userid']; - protocol = json['protocol']; - fields = (json['fields'] as Map).copy(); - } - - Map toJson() { - final data = {}; - data['userid'] = userId; - data['protocol'] = protocol; - data['fields'] = fields; - return data; - } -} diff --git a/lib/matrix_api/model/timeline_history_response.dart b/lib/matrix_api/model/timeline_history_response.dart deleted file mode 100644 index e5752762..00000000 --- a/lib/matrix_api/model/timeline_history_response.dart +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_event.dart'; - -class TimelineHistoryResponse { - String start; - String end; - List chunk; - List state; - - TimelineHistoryResponse.fromJson(Map json) { - start = json['start']; - end = json['end']; - chunk = json['chunk'] != null - ? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - state = json['state'] != null - ? (json['state'] as List).map((i) => MatrixEvent.fromJson(i)).toList() - : null; - } - - Map toJson() { - final data = {}; - if (start != null) data['start'] = start; - if (end != null) data['end'] = end; - if (chunk != null) data['chunk'] = chunk.map((i) => i.toJson()); - if (state != null) data['state'] = state.map((i) => i.toJson()); - return data; - } -} diff --git a/lib/matrix_api/model/turn_server_credentials.dart b/lib/matrix_api/model/turn_server_credentials.dart deleted file mode 100644 index bf350f50..00000000 --- a/lib/matrix_api/model/turn_server_credentials.dart +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class TurnServerCredentials { - String username; - String password; - List uris; - num ttl; - - TurnServerCredentials.fromJson(Map json) { - username = json['username']; - password = json['password']; - uris = json['uris'].cast(); - ttl = json['ttl']; - } - - Map toJson() { - final data = {}; - data['username'] = username; - data['password'] = password; - data['uris'] = uris; - data['ttl'] = ttl; - return data; - } -} diff --git a/lib/matrix_api/model/upload_key_signatures_response.dart b/lib/matrix_api/model/upload_key_signatures_response.dart deleted file mode 100644 index 325aa5e7..00000000 --- a/lib/matrix_api/model/upload_key_signatures_response.dart +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'matrix_exception.dart'; - -class UploadKeySignaturesResponse { - Map> failures; - - UploadKeySignaturesResponse.fromJson(Map json) { - failures = json['failures'] != null - ? (json['failures'] as Map).map( - (k, v) => MapEntry( - k, - (v as Map).map((k, v) => MapEntry( - k, - MatrixException.fromJson(v), - )), - ), - ) - : null; - } - - Map toJson() { - final data = {}; - if (failures != null) { - data['failures'] = failures.map( - (k, v) => MapEntry( - k, - v.map( - (k, v) => MapEntry( - k, - v.raw, - ), - ), - ), - ); - } - return data; - } -} diff --git a/lib/matrix_api/model/user_search_result.dart b/lib/matrix_api/model/user_search_result.dart deleted file mode 100644 index 1d498083..00000000 --- a/lib/matrix_api/model/user_search_result.dart +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'profile.dart'; - -class UserSearchResult { - List results; - bool limited; - - UserSearchResult.fromJson(Map json) { - results = []; - json['results'].forEach((v) { - results.add(Profile.fromJson(v)); - }); - - limited = json['limited']; - } - - Map toJson() { - final data = {}; - data['results'] = results.map((v) => v.toJson()).toList(); - - data['limited'] = limited; - return data; - } -} diff --git a/lib/matrix_api/model/well_known_informations.dart b/lib/matrix_api/model/well_known_informations.dart deleted file mode 100644 index feba960c..00000000 --- a/lib/matrix_api/model/well_known_informations.dart +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class WellKnownInformations { - MHomeserver mHomeserver; - MHomeserver mIdentityServer; - Map content; - - WellKnownInformations.fromJson(Map 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; - } - - Map toJson() { - final data = content; - data['m.homeserver'] = mHomeserver.toJson(); - data['m.identity_server'] = mIdentityServer.toJson(); - return data; - } -} - -class MHomeserver { - String baseUrl; - - MHomeserver.fromJson(Map json) { - baseUrl = json['base_url']; - } - - Map toJson() { - final data = {}; - data['base_url'] = baseUrl; - return data; - } -} diff --git a/lib/matrix_api/model/who_is_info.dart b/lib/matrix_api/model/who_is_info.dart deleted file mode 100644 index 6a266852..00000000 --- a/lib/matrix_api/model/who_is_info.dart +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -class WhoIsInfo { - String userId; - Map devices; - - WhoIsInfo.fromJson(Map json) { - userId = json['user_id']; - devices = json['devices'] != null - ? (json['devices'] as Map) - .map((k, v) => MapEntry(k, DeviceInfo.fromJson(v))) - : null; - } - - Map toJson() { - final data = {}; - data['user_id'] = userId; - if (devices != null) { - data['devices'] = devices.map((k, v) => MapEntry(k, v.toJson())); - } - return data; - } -} - -class DeviceInfo { - List sessions; - - DeviceInfo.fromJson(Map json) { - if (json['sessions'] != null) { - sessions = []; - json['sessions'].forEach((v) { - sessions.add(Sessions.fromJson(v)); - }); - } - } - - Map toJson() { - final data = {}; - if (sessions != null) { - data['sessions'] = sessions.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class Sessions { - List connections; - - Sessions.fromJson(Map json) { - if (json['connections'] != null) { - connections = []; - json['connections'].forEach((v) { - connections.add(Connections.fromJson(v)); - }); - } - } - - Map toJson() { - final data = {}; - if (connections != null) { - data['connections'] = connections.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class Connections { - String ip; - int lastSeen; - String userAgent; - - Connections.fromJson(Map json) { - ip = json['ip']; - lastSeen = json['last_seen']; - userAgent = json['user_agent']; - } - - Map toJson() { - final data = {}; - if (ip != null) { - data['ip'] = ip; - } - if (lastSeen != null) { - data['last_seen'] = lastSeen; - } - if (userAgent != null) { - data['user_agent'] = userAgent; - } - return data; - } -} diff --git a/lib/matrix_api/utils/logs.dart b/lib/matrix_api/utils/logs.dart deleted file mode 100644 index 7e15f379..00000000 --- a/lib/matrix_api/utils/logs.dart +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'package:logger/logger.dart'; - -class Logs extends Logger { - static final Logs _singleton = Logs._internal(); - - factory Logs() { - return _singleton; - } - - set level(Level newLevel) => Logger.level = newLevel; - - final List outputEvents = []; - - Logs._internal() - : super( - printer: PrettyPrinter(methodCount: 0, lineLength: 100), - filter: _MatrixSdkFilter(), - output: _CacheOutput(), - ); -} - -class _MatrixSdkFilter extends LogFilter { - @override - bool shouldLog(LogEvent event) => event.level.index >= Logger.level.index; -} - -class _CacheOutput extends ConsoleOutput { - @override - void output(OutputEvent event) { - Logs().outputEvents.add(event); - super.output(event); - } -} diff --git a/lib/matrix_api/utils/try_get_map_extension.dart b/lib/matrix_api/utils/try_get_map_extension.dart deleted file mode 100644 index fe8f306c..00000000 --- a/lib/matrix_api/utils/try_get_map_extension.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'logs.dart'; - -extension TryGetMapExtension on Map { - T tryGet(String key, [T fallbackValue]) { - 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 value; - } -} diff --git a/lib/src/client.dart b/lib/src/client.dart index bafc82d7..bb03aabb 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -26,7 +26,6 @@ import 'package:pedantic/pedantic.dart'; import '../encryption.dart'; import '../famedlysdk.dart'; -import '../matrix_api/utils/logs.dart'; import 'database/database.dart' show Database; import 'event.dart'; import 'room.dart'; diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index 446bcb7e..533777e4 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -4,8 +4,7 @@ import 'dart:convert'; import 'package:moor/moor.dart'; import '../../famedlysdk.dart' as sdk; -import '../../matrix_api.dart' as api; -import '../../matrix_api/utils/logs.dart'; +import 'package:matrix_api_lite/matrix_api_lite.dart' as api; import '../client.dart'; import '../room.dart'; @@ -66,7 +65,7 @@ class Database extends _$Database { try { await m.createAll(); } catch (e, s) { - Logs().e('Create all failed in database migrator', e, s); + api.Logs().e('Create all failed in database migrator', e, s); onError.add(SdkError(exception: e, stackTrace: s)); rethrow; } @@ -148,7 +147,7 @@ class Database extends _$Database { from++; } } catch (e, s) { - Logs().e('Database migration failed', e, s); + api.Logs().e('Database migration failed', e, s); onError.add(SdkError(exception: e, stackTrace: s)); rethrow; } @@ -158,12 +157,12 @@ class Database extends _$Database { if (executor.dialect == SqlDialect.sqlite) { final ret = await customSelect('PRAGMA journal_mode=WAL').get(); if (ret.isNotEmpty) { - Logs().v('[Moor] Switched database to mode ' + + api.Logs().v('[Moor] Switched database to mode ' + ret.first.data['journal_mode'].toString()); } } } catch (e, s) { - Logs().e('Database before open failed', e, s); + api.Logs().e('Database before open failed', e, s); onError.add(SdkError(exception: e, stackTrace: s)); rethrow; } diff --git a/lib/src/event.dart b/lib/src/event.dart index 6fe4e8d9..56ad9bfa 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -23,7 +23,6 @@ import 'package:http/http.dart' as http; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; import '../famedlysdk.dart'; -import '../matrix_api.dart'; import 'database/database.dart' show DbRoomState, DbEvent; import 'room.dart'; import 'utils/matrix_localizations.dart'; diff --git a/lib/src/room.dart b/lib/src/room.dart index 54ae8c5f..c283fb80 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -18,21 +18,18 @@ import 'dart:async'; -import 'package:famedlysdk/matrix_api/model/marked_unread.dart'; import 'package:html_unescape/html_unescape.dart'; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; import '../famedlysdk.dart'; -import '../matrix_api.dart'; import 'client.dart'; import 'database/database.dart' show DbRoom; import 'event.dart'; import 'timeline.dart'; import 'user.dart'; import 'utils/event_update.dart'; -import '../matrix_api/utils/logs.dart'; -import '../matrix_api/utils/try_get_map_extension.dart'; import 'utils/markdown.dart'; +import 'utils/marked_unread.dart'; import 'utils/matrix_file.dart'; import 'utils/matrix_localizations.dart'; import 'utils/states_map.dart'; diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 52879bb7..48cd04b2 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -18,11 +18,10 @@ import 'dart:async'; -import '../matrix_api.dart'; +import '../famedlysdk.dart'; import 'event.dart'; import 'room.dart'; import 'utils/event_update.dart'; -import '../matrix_api/utils/logs.dart'; import 'utils/room_update.dart'; typedef onTimelineUpdateCallback = void Function(); diff --git a/lib/src/user.dart b/lib/src/user.dart index f762e4a5..d8ab1a59 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -17,7 +17,7 @@ */ import '../famedlysdk.dart'; -import '../matrix_api.dart'; + import 'event.dart'; import 'room.dart'; diff --git a/lib/src/utils/device_keys_list.dart b/lib/src/utils/device_keys_list.dart index 31c2e368..ec8e306e 100644 --- a/lib/src/utils/device_keys_list.dart +++ b/lib/src/utils/device_keys_list.dart @@ -1,10 +1,11 @@ import 'dart:convert'; import 'package:canonical_json/canonical_json.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:olm/olm.dart' as olm; import '../../encryption.dart'; -import '../../matrix_api.dart'; + import '../client.dart'; import '../database/database.dart' show DbUserDeviceKey, DbUserDeviceKeysKey, DbUserCrossSigningKey; diff --git a/lib/src/utils/event_localizations.dart b/lib/src/utils/event_localizations.dart index aa55f9b3..b3b8b639 100644 --- a/lib/src/utils/event_localizations.dart +++ b/lib/src/utils/event_localizations.dart @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import '../../matrix_api.dart'; import '../../encryption.dart'; +import '../../famedlysdk.dart'; import '../event.dart'; import '../room.dart'; import 'matrix_localizations.dart'; diff --git a/lib/src/utils/event_update.dart b/lib/src/utils/event_update.dart index df9734aa..1daa5169 100644 --- a/lib/src/utils/event_update.dart +++ b/lib/src/utils/event_update.dart @@ -17,8 +17,6 @@ */ import '../../famedlysdk.dart'; -import '../../matrix_api.dart'; -import '../../matrix_api/utils/logs.dart'; enum EventUpdateType { timeline, diff --git a/lib/matrix_api/utils/map_copy_extension.dart b/lib/src/utils/map_copy_extension.dart similarity index 100% rename from lib/matrix_api/utils/map_copy_extension.dart rename to lib/src/utils/map_copy_extension.dart diff --git a/lib/matrix_api/model/marked_unread.dart b/lib/src/utils/marked_unread.dart similarity index 96% rename from lib/matrix_api/model/marked_unread.dart rename to lib/src/utils/marked_unread.dart index c3223c78..6dc3e327 100644 --- a/lib/matrix_api/model/marked_unread.dart +++ b/lib/src/utils/marked_unread.dart @@ -1,6 +1,6 @@ /* * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH + * Copyright (C) 2019, 2020, 2021 Famedly GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/lib/src/utils/matrix_file.dart b/lib/src/utils/matrix_file.dart index bfc0f3df..1f2e176c 100644 --- a/lib/src/utils/matrix_file.dart +++ b/lib/src/utils/matrix_file.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; import 'package:mime/mime.dart'; -import '../../matrix_api/model/message_types.dart'; +import '../../famedlysdk.dart'; class MatrixFile { Uint8List bytes; diff --git a/lib/src/utils/room_update.dart b/lib/src/utils/room_update.dart index bdb918f0..bef678c1 100644 --- a/lib/src/utils/room_update.dart +++ b/lib/src/utils/room_update.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import '../../matrix_api.dart'; +import '../../famedlysdk.dart'; /// Represents a new room or an update for an /// already known room. diff --git a/lib/src/utils/run_in_root.dart b/lib/src/utils/run_in_root.dart index f6df1fa8..b7fda622 100644 --- a/lib/src/utils/run_in_root.dart +++ b/lib/src/utils/run_in_root.dart @@ -18,7 +18,7 @@ import 'dart:async'; -import '../../matrix_api/utils/logs.dart'; +import '../../famedlysdk.dart'; Future runInRoot(FutureOr Function() fn) async { return await Zone.root.run(() async { diff --git a/lib/src/utils/states_map.dart b/lib/src/utils/states_map.dart index 4af43226..5f3f190b 100644 --- a/lib/src/utils/states_map.dart +++ b/lib/src/utils/states_map.dart @@ -1,5 +1,4 @@ import '../../famedlysdk.dart'; -import '../../matrix_api.dart'; /// Matrix room states are addressed by a tuple of the [type] and an /// optional [stateKey]. diff --git a/lib/src/utils/sync_update_extension.dart b/lib/src/utils/sync_update_extension.dart index a14150fa..c8e85b0e 100644 --- a/lib/src/utils/sync_update_extension.dart +++ b/lib/src/utils/sync_update_extension.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import '../../matrix_api.dart'; +import '../../famedlysdk.dart'; /// This extension adds easy-to-use filters for the sync update, meant to be used on the `client.onSync` stream, e.g. /// `client.onSync.stream.where((s) => s.hasRoomUpdate)`. Multiple filters can easily be diff --git a/lib/src/utils/to_device_event.dart b/lib/src/utils/to_device_event.dart index 96ff91bc..4abcf329 100644 --- a/lib/src/utils/to_device_event.dart +++ b/lib/src/utils/to_device_event.dart @@ -1,4 +1,4 @@ -import '../../matrix_api.dart'; +import '../../famedlysdk.dart'; class ToDeviceEvent extends BasicEventWithSender { Map encryptedContent; diff --git a/pubspec.yaml b/pubspec.yaml index 3ea252db..57dda557 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,9 @@ dependencies: matrix_file_e2ee: ^1.0.5 isolate: ^2.0.3 logger: ^0.9.4 + matrix_api_lite: + git: + url: https://gitlab.com/famedly/libraries/matrix_api_lite.git dev_dependencies: test: ^1.15.7 diff --git a/test/canonical_json_test.dart b/test/canonical_json_test.dart index 93731e53..a357d4e1 100644 --- a/test/canonical_json_test.dart +++ b/test/canonical_json_test.dart @@ -17,7 +17,7 @@ */ import 'package:canonical_json/canonical_json.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; diff --git a/test/client_test.dart b/test/client_test.dart index ba49f55a..bcd0631c 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -21,8 +21,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; + import 'package:famedlysdk/src/client.dart'; import 'package:famedlysdk/src/utils/event_update.dart'; import 'package:famedlysdk/src/utils/matrix_file.dart'; diff --git a/test/device_keys_list_test.dart b/test/device_keys_list_test.dart index df68a179..b0b71ea4 100644 --- a/test/device_keys_list_test.dart +++ b/test/device_keys_list_test.dart @@ -19,7 +19,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/bootstrap_test.dart b/test/encryption/bootstrap_test.dart index 5b257d40..d484aeca 100644 --- a/test/encryption/bootstrap_test.dart +++ b/test/encryption/bootstrap_test.dart @@ -21,7 +21,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/encryption.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/cross_signing_test.dart b/test/encryption/cross_signing_test.dart index 52d73bbe..ba64a2a2 100644 --- a/test/encryption/cross_signing_test.dart +++ b/test/encryption/cross_signing_test.dart @@ -19,7 +19,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/encrypt_decrypt_room_message_test.dart b/test/encryption/encrypt_decrypt_room_message_test.dart index a8903b10..a1f54cff 100644 --- a/test/encryption/encrypt_decrypt_room_message_test.dart +++ b/test/encryption/encrypt_decrypt_room_message_test.dart @@ -17,7 +17,6 @@ */ import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/encrypt_decrypt_to_device_test.dart b/test/encryption/encrypt_decrypt_to_device_test.dart index 0d84b227..343ac837 100644 --- a/test/encryption/encrypt_decrypt_to_device_test.dart +++ b/test/encryption/encrypt_decrypt_to_device_test.dart @@ -17,7 +17,6 @@ */ import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/key_manager_test.dart b/test/encryption/key_manager_test.dart index 4d51c2d5..fd7be177 100644 --- a/test/encryption/key_manager_test.dart +++ b/test/encryption/key_manager_test.dart @@ -19,7 +19,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/key_request_test.dart b/test/encryption/key_request_test.dart index 84dc1c13..45486a62 100644 --- a/test/encryption/key_request_test.dart +++ b/test/encryption/key_request_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/key_verification_test.dart b/test/encryption/key_verification_test.dart index e003d1f1..6ecb8c0d 100644 --- a/test/encryption/key_verification_test.dart +++ b/test/encryption/key_verification_test.dart @@ -20,7 +20,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/encryption.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/olm_manager_test.dart b/test/encryption/olm_manager_test.dart index ba1e7646..c1959cf5 100644 --- a/test/encryption/olm_manager_test.dart +++ b/test/encryption/olm_manager_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/online_key_backup_test.dart b/test/encryption/online_key_backup_test.dart index 957bc0a6..a9a933d3 100644 --- a/test/encryption/online_key_backup_test.dart +++ b/test/encryption/online_key_backup_test.dart @@ -19,8 +19,6 @@ import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/encryption/ssss_test.dart b/test/encryption/ssss_test.dart index de7594eb..ee91c8d0 100644 --- a/test/encryption/ssss_test.dart +++ b/test/encryption/ssss_test.dart @@ -20,9 +20,7 @@ import 'dart:typed_data'; import 'dart:convert'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/encryption.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:encrypt/encrypt.dart'; diff --git a/test/event_test.dart b/test/event_test.dart index a3b6d3d7..6bbcdeac 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -20,10 +20,8 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/encryption.dart'; import 'package:famedlysdk/src/event.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; diff --git a/test/fake_matrix_api.dart b/test/fake_matrix_api.dart index f9f6bcde..395fc58e 100644 --- a/test/fake_matrix_api.dart +++ b/test/fake_matrix_api.dart @@ -17,12 +17,12 @@ */ import 'package:famedlysdk/famedlysdk.dart' as sdk; +import 'package:famedlysdk/famedlysdk.dart'; import 'dart:convert'; import 'dart:core'; import 'dart:math'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:http/http.dart'; import 'package:http/testing.dart'; diff --git a/test/matrix_api/map_copy_extension_test.dart b/test/matrix_api/map_copy_extension_test.dart index 3e21cf40..1e8edcdb 100644 --- a/test/matrix_api/map_copy_extension_test.dart +++ b/test/matrix_api/map_copy_extension_test.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import 'package:famedlysdk/matrix_api/utils/map_copy_extension.dart'; +import 'package:famedlysdk/src/utils/map_copy_extension.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/matrix_api/try_get_map_extension_test.dart b/test/matrix_api/try_get_map_extension_test.dart index 646d7348..886700e3 100644 --- a/test/matrix_api/try_get_map_extension_test.dart +++ b/test/matrix_api/try_get_map_extension_test.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import 'package:famedlysdk/matrix_api/utils/try_get_map_extension.dart'; +import 'package:matrix_api_lite/matrix_api_lite.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 80e11452..b647b927 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -17,15 +17,7 @@ */ import 'dart:typed_data'; - -import 'package:famedlysdk/matrix_api.dart'; -import 'package:famedlysdk/matrix_api/model/filter.dart'; -import 'package:famedlysdk/matrix_api/model/matrix_exception.dart'; -import 'package:famedlysdk/matrix_api/model/matrix_keys.dart'; -import 'package:famedlysdk/matrix_api/model/presence_content.dart'; -import 'package:famedlysdk/matrix_api/model/push_rule_set.dart'; -import 'package:famedlysdk/matrix_api/model/pusher.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; diff --git a/test/matrix_exception_test.dart b/test/matrix_exception_test.dart index d71ce02e..d6982ab3 100644 --- a/test/matrix_exception_test.dart +++ b/test/matrix_exception_test.dart @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import 'package:famedlysdk/matrix_api.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:http/http.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; diff --git a/test/mxc_uri_extension_test.dart b/test/mxc_uri_extension_test.dart index 8b03d457..3949fd20 100644 --- a/test/mxc_uri_extension_test.dart +++ b/test/mxc_uri_extension_test.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import 'package:famedlysdk/matrix_api/utils/logs.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:famedlysdk/src/client.dart'; diff --git a/test/room_test.dart b/test/room_test.dart index ff9c711c..36f4df35 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -19,7 +19,7 @@ import 'dart:convert'; import 'dart:typed_data'; -import 'package:famedlysdk/matrix_api.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/src/client.dart'; import 'package:famedlysdk/src/database/database.dart' show DbRoom, DbRoomState, DbRoomAccountData; diff --git a/test/timeline_test.dart b/test/timeline_test.dart index de00e626..cf543238 100644 --- a/test/timeline_test.dart +++ b/test/timeline_test.dart @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import 'package:famedlysdk/matrix_api.dart'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:logger/logger.dart'; import 'package:test/test.dart'; import 'package:famedlysdk/src/client.dart'; diff --git a/test/user_test.dart b/test/user_test.dart index e3d19ebc..f3a1ef1b 100644 --- a/test/user_test.dart +++ b/test/user_test.dart @@ -17,7 +17,6 @@ */ import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/src/event.dart'; import 'package:famedlysdk/src/user.dart'; import 'package:logger/logger.dart'; diff --git a/test_driver/famedlysdk_test.dart b/test_driver/famedlysdk_test.dart index 1bae4031..3f2ccec1 100644 --- a/test_driver/famedlysdk_test.dart +++ b/test_driver/famedlysdk_test.dart @@ -1,6 +1,4 @@ import 'package:famedlysdk/famedlysdk.dart'; -import 'package:famedlysdk/matrix_api.dart'; -import 'package:famedlysdk/matrix_api/utils/logs.dart'; import '../test/fake_database.dart'; import 'test_config.dart'; import 'package:olm/olm.dart' as olm;