fix: Current version

This commit is contained in:
Christian Pauly 2020-12-31 10:33:59 +01:00
parent 3340a1e540
commit 68e6530835
13 changed files with 64 additions and 20 deletions

View File

@ -20,6 +20,7 @@ library matrix_api_lite;
export 'src/matrix_api.dart'; export 'src/matrix_api.dart';
export 'src/utils/logs.dart'; export 'src/utils/logs.dart';
export 'src/utils/map_copy_extension.dart';
export 'src/utils/try_get_map_extension.dart'; export 'src/utils/try_get_map_extension.dart';
export 'src/model/algorithm_types.dart'; export 'src/model/algorithm_types.dart';
export 'src/model/basic_event.dart'; export 'src/model/basic_event.dart';

View File

@ -17,6 +17,7 @@
*/ */
import 'authentication_user_identifier.dart'; import 'authentication_user_identifier.dart';
import 'authentication_data.dart'; import 'authentication_data.dart';
import 'authentication_identifier.dart'; import 'authentication_identifier.dart';
import 'authentication_phone_identifier.dart'; import 'authentication_phone_identifier.dart';

View File

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
class BasicEvent { class BasicEvent {
String type; String type;
Map<String, dynamic> content; Map<String, dynamic> content;
@ -27,7 +29,7 @@ class BasicEvent {
BasicEvent.fromJson(Map<String, dynamic> json) { BasicEvent.fromJson(Map<String, dynamic> json) {
type = json['type']; type = json['type'];
content = Map<String, dynamic>.from(json['content']); content = (json['content'] as Map<String, dynamic>).copy();
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -17,6 +17,7 @@
*/ */
import 'matrix_keys.dart'; import 'matrix_keys.dart';
import '../utils/map_copy_extension.dart';
class KeysQueryResponse { class KeysQueryResponse {
Map<String, dynamic> failures; Map<String, dynamic> failures;
@ -26,9 +27,7 @@ class KeysQueryResponse {
Map<String, MatrixCrossSigningKey> userSigningKeys; Map<String, MatrixCrossSigningKey> userSigningKeys;
KeysQueryResponse.fromJson(Map<String, dynamic> json) { KeysQueryResponse.fromJson(Map<String, dynamic> json) {
failures = json['failures'] != null failures = (json['failures'] as Map<String, dynamic>)?.copy();
? Map<String, dynamic>.from(json['failures'])
: null;
deviceKeys = json['device_keys'] != null deviceKeys = json['device_keys'] != null
? (json['device_keys'] as Map).map( ? (json['device_keys'] as Map).map(
(k, v) => MapEntry( (k, v) => MapEntry(

View File

@ -17,6 +17,7 @@
*/ */
import 'stripped_state_event.dart'; import 'stripped_state_event.dart';
import '../utils/map_copy_extension.dart';
class MatrixEvent extends StrippedStateEvent { class MatrixEvent extends StrippedStateEvent {
String eventId; String eventId;
@ -38,12 +39,8 @@ class MatrixEvent extends StrippedStateEvent {
roomId = json['room_id']; roomId = json['room_id'];
originServerTs = originServerTs =
DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']); DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']);
unsigned = json['unsigned'] != null unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
? Map<String, dynamic>.from(json['unsigned']) prevContent = (json['prev_content'] as Map<String, dynamic>)?.copy();
: null;
prevContent = json['prev_content'] != null
? Map<String, dynamic>.from(json['prev_content'])
: null;
redacts = json['redacts']; redacts = json['redacts'];
} }

View File

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
class MatrixSignableKey { class MatrixSignableKey {
String userId; String userId;
String identifier; String identifier;
@ -33,13 +35,12 @@ class MatrixSignableKey {
_json = json; _json = json;
userId = json['user_id']; userId = json['user_id'];
keys = Map<String, String>.from(json['keys']); keys = Map<String, String>.from(json['keys']);
// we need to manually copy to ensure that our map is Map<String, Map<String, String>>
signatures = json['signatures'] is Map signatures = json['signatures'] is Map
? Map<String, Map<String, String>>.from((json['signatures'] as Map) ? Map<String, Map<String, String>>.from((json['signatures'] as Map)
.map((k, v) => MapEntry(k, Map<String, String>.from(v)))) .map((k, v) => MapEntry(k, Map<String, String>.from(v))))
: null; : null;
unsigned = json['unsigned'] is Map unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
? Map<String, dynamic>.from(json['unsigned'])
: null;
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -16,13 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
class OneTimeKeysClaimResponse { class OneTimeKeysClaimResponse {
Map<String, dynamic> failures; Map<String, dynamic> failures;
Map<String, Map<String, dynamic>> oneTimeKeys; Map<String, Map<String, dynamic>> oneTimeKeys;
OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json) { OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json) {
failures = Map<String, dynamic>.from(json['failures'] ?? {}); failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {};
oneTimeKeys = Map<String, Map<String, dynamic>>.from(json['one_time_keys']); // We still need a Map<...>.from(...) to ensure all second-level entries are also maps
oneTimeKeys = Map<String, Map<String, dynamic>>.from(
(json['one_time_keys'] as Map<String, dynamic>).copy());
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import 'algorithm_types.dart'; import '../../matrix_api_lite.dart';
enum RoomKeysAlgorithmType { v1Curve25519AesSha2 } enum RoomKeysAlgorithmType { v1Curve25519AesSha2 }

View File

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
enum RoomVersionStability { stable, unstable } enum RoomVersionStability { stable, unstable }
class ServerCapabilities { class ServerCapabilities {
@ -30,7 +32,7 @@ class ServerCapabilities {
mRoomVersions = json['m.room_versions'] != null mRoomVersions = json['m.room_versions'] != null
? MRoomVersions.fromJson(json['m.room_versions']) ? MRoomVersions.fromJson(json['m.room_versions'])
: null; : null;
customCapabilities = Map<String, dynamic>.from(json); customCapabilities = json.copy();
customCapabilities.remove('m.change_password'); customCapabilities.remove('m.change_password');
customCapabilities.remove('m.room_versions'); customCapabilities.remove('m.room_versions');
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../../matrix_api_lite.dart'; import '../matrix_api.dart';
class ThirdPartyIdentifier { class ThirdPartyIdentifier {
ThirdPartyIdentifierMedium medium; ThirdPartyIdentifierMedium medium;

View File

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
class ThirdPartyLocation { class ThirdPartyLocation {
String alias; String alias;
String protocol; String protocol;
@ -24,7 +26,7 @@ class ThirdPartyLocation {
ThirdPartyLocation.fromJson(Map<String, dynamic> json) { ThirdPartyLocation.fromJson(Map<String, dynamic> json) {
alias = json['alias']; alias = json['alias'];
protocol = json['protocol']; protocol = json['protocol'];
fields = Map<String, dynamic>.from(json['fields']); fields = (json['fields'] as Map<String, dynamic>).copy();
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../utils/map_copy_extension.dart';
class ThirdPartyUser { class ThirdPartyUser {
String userId; String userId;
String protocol; String protocol;
@ -24,7 +26,7 @@ class ThirdPartyUser {
ThirdPartyUser.fromJson(Map<String, dynamic> json) { ThirdPartyUser.fromJson(Map<String, dynamic> json) {
userId = json['userid']; userId = json['userid'];
protocol = json['protocol']; protocol = json['protocol'];
fields = Map<String, dynamic>.from(json['fields']); fields = (json['fields'] as Map<String, dynamic>).copy();
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -0,0 +1,33 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
extension MapCopyExtension on Map<String, dynamic> {
/// Deep-copies a given json map
Map<String, dynamic> copy() {
final copy = Map<String, dynamic>.from(this);
for (final entry in copy.entries) {
if (entry.value is Map<String, dynamic>) {
copy[entry.key] = (entry.value as Map<String, dynamic>).copy();
}
if (entry.value is List) {
copy[entry.key] = List.from(entry.value);
}
}
return copy;
}
}