From 978c3bb994f6b0765a0c1e9313aaf169257babcf Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 13 Oct 2021 17:03:34 +0200 Subject: [PATCH] refactor: make voip_content nullsafe --- lib/src/voip_content.dart | 72 +++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/lib/src/voip_content.dart b/lib/src/voip_content.dart index 6f34969b..1ac24ebf 100644 --- a/lib/src/voip_content.dart +++ b/lib/src/voip_content.dart @@ -1,8 +1,25 @@ -// @dart=2.9 +/* + * Famedly Matrix SDK + * Copyright (C) 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 + * 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 CallReplacesTarget { - String id; - String display_name; - String avatar_url; + String? id; + String? display_name; + String? avatar_url; CallReplacesTarget({this.id, this.display_name, this.avatar_url}); factory CallReplacesTarget.fromJson(Map json) => @@ -22,11 +39,11 @@ class CallReplacesTarget { /// MSC2747: VoIP call transfers /// https://github.com/matrix-org/matrix-doc/pull/2747 class CallReplaces { - String replacement_id; - CallReplacesTarget target_user; - String create_call; - String await_call; - String target_room; + String? replacement_id; + CallReplacesTarget? target_user; + String? create_call; + String? await_call; + String? target_room; CallReplaces({ this.replacement_id, @@ -36,16 +53,16 @@ class CallReplaces { this.target_room, }); factory CallReplaces.fromJson(Map json) => CallReplaces( - replacement_id: json['replacement_id'].toString(), - create_call: json['create_call'].toString(), - await_call: json['await_call'].toString(), - target_room: json['target_room'].toString(), + replacement_id: json['replacement_id']?.toString(), + create_call: json['create_call']?.toString(), + await_call: json['await_call']?.toString(), + target_room: json['target_room']?.toString(), target_user: CallReplacesTarget.fromJson(json['target_user']), ); Map toJson() => { if (replacement_id != null) 'replacement_id': replacement_id, - if (target_user != null) 'target_user': target_user.toJson(), + if (target_user != null) 'target_user': target_user!.toJson(), if (create_call != null) 'create_call': create_call, if (await_call != null) 'await_call': await_call, if (target_room != null) 'target_room': target_room, @@ -60,11 +77,11 @@ const String sdpStreamMetadataKey = 'org.matrix.msc3077.sdp_stream_metadata'; class CallCapabilities { bool transferee; bool dtmf; - CallCapabilities({this.transferee, this.dtmf}); + CallCapabilities({this.transferee = false, this.dtmf = false}); factory CallCapabilities.fromJson(Map json) => CallCapabilities( - dtmf: json['m.call.dtmf'] as bool ?? false, - transferee: json['m.call.transferee'] as bool ?? false, + dtmf: json['m.call.dtmf'] as bool? ?? false, + transferee: json['m.call.transferee'] as bool? ?? false, ); Map toJson() => { if (transferee != null) 'm.call.transferee': transferee, @@ -88,11 +105,14 @@ class SDPStreamPurpose { bool audio_muted; bool video_muted; - SDPStreamPurpose({this.purpose, this.audio_muted, this.video_muted}); + SDPStreamPurpose( + {required this.purpose, + this.audio_muted = false, + this.video_muted = false}); factory SDPStreamPurpose.fromJson(Map json) => SDPStreamPurpose( - audio_muted: json['audio_muted'] as bool ?? false, - video_muted: json['video_muted'] as bool ?? false, + audio_muted: json['audio_muted'] as bool? ?? false, + video_muted: json['video_muted'] as bool? ?? false, purpose: json['purpose'] as String, ); @@ -122,15 +142,15 @@ class SDPStreamMetadata { /// MSC3086: Asserted identity on VoIP calls /// https://github.com/matrix-org/matrix-doc/pull/3086 class AssertedIdentity { - String id; - String displayName; - String avatarUrl; + String? id; + String? displayName; + String? avatarUrl; AssertedIdentity({this.id, this.displayName, this.avatarUrl}); factory AssertedIdentity.fromJson(Map json) => AssertedIdentity( - displayName: json['display_name'] as String, - id: json['id'] as String, - avatarUrl: json['avatar_url'] as String, + displayName: json['display_name'] as String?, + id: json['id'] as String?, + avatarUrl: json['avatar_url'] as String?, ); Map toJson() => { if (displayName != null) 'display_name': displayName,