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/utils/logs.dart';
export 'src/utils/map_copy_extension.dart';
export 'src/utils/try_get_map_extension.dart';
export 'src/model/algorithm_types.dart';
export 'src/model/basic_event.dart';

View File

@ -17,6 +17,7 @@
*/
import 'authentication_user_identifier.dart';
import 'authentication_data.dart';
import 'authentication_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/>.
*/
import '../utils/map_copy_extension.dart';
class BasicEvent {
String type;
Map<String, dynamic> content;
@ -27,7 +29,7 @@ class BasicEvent {
BasicEvent.fromJson(Map<String, dynamic> json) {
type = json['type'];
content = Map<String, dynamic>.from(json['content']);
content = (json['content'] as Map<String, dynamic>).copy();
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};

View File

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

View File

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

View File

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

View File

@ -16,13 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import '../utils/map_copy_extension.dart';
class OneTimeKeysClaimResponse {
Map<String, dynamic> failures;
Map<String, Map<String, dynamic>> oneTimeKeys;
OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json) {
failures = Map<String, dynamic>.from(json['failures'] ?? {});
oneTimeKeys = Map<String, Map<String, dynamic>>.from(json['one_time_keys']);
failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {};
// 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() {

View File

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

View File

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

View File

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

View File

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

View File

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