refactor: make voip_content nullsafe

This commit is contained in:
Nicolas Werner 2021-10-13 17:03:34 +02:00
parent 60956bde00
commit 978c3bb994
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 46 additions and 26 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
class CallReplacesTarget { class CallReplacesTarget {
String id; String? id;
String display_name; String? display_name;
String avatar_url; String? avatar_url;
CallReplacesTarget({this.id, this.display_name, this.avatar_url}); CallReplacesTarget({this.id, this.display_name, this.avatar_url});
factory CallReplacesTarget.fromJson(Map<String, dynamic> json) => factory CallReplacesTarget.fromJson(Map<String, dynamic> json) =>
@ -22,11 +39,11 @@ class CallReplacesTarget {
/// MSC2747: VoIP call transfers /// MSC2747: VoIP call transfers
/// https://github.com/matrix-org/matrix-doc/pull/2747 /// https://github.com/matrix-org/matrix-doc/pull/2747
class CallReplaces { class CallReplaces {
String replacement_id; String? replacement_id;
CallReplacesTarget target_user; CallReplacesTarget? target_user;
String create_call; String? create_call;
String await_call; String? await_call;
String target_room; String? target_room;
CallReplaces({ CallReplaces({
this.replacement_id, this.replacement_id,
@ -36,16 +53,16 @@ class CallReplaces {
this.target_room, this.target_room,
}); });
factory CallReplaces.fromJson(Map<String, dynamic> json) => CallReplaces( factory CallReplaces.fromJson(Map<String, dynamic> json) => CallReplaces(
replacement_id: json['replacement_id'].toString(), replacement_id: json['replacement_id']?.toString(),
create_call: json['create_call'].toString(), create_call: json['create_call']?.toString(),
await_call: json['await_call'].toString(), await_call: json['await_call']?.toString(),
target_room: json['target_room'].toString(), target_room: json['target_room']?.toString(),
target_user: CallReplacesTarget.fromJson(json['target_user']), target_user: CallReplacesTarget.fromJson(json['target_user']),
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
if (replacement_id != null) 'replacement_id': replacement_id, 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 (create_call != null) 'create_call': create_call,
if (await_call != null) 'await_call': await_call, if (await_call != null) 'await_call': await_call,
if (target_room != null) 'target_room': target_room, if (target_room != null) 'target_room': target_room,
@ -60,11 +77,11 @@ const String sdpStreamMetadataKey = 'org.matrix.msc3077.sdp_stream_metadata';
class CallCapabilities { class CallCapabilities {
bool transferee; bool transferee;
bool dtmf; bool dtmf;
CallCapabilities({this.transferee, this.dtmf}); CallCapabilities({this.transferee = false, this.dtmf = false});
factory CallCapabilities.fromJson(Map<String, dynamic> json) => factory CallCapabilities.fromJson(Map<String, dynamic> json) =>
CallCapabilities( CallCapabilities(
dtmf: json['m.call.dtmf'] as bool ?? false, dtmf: json['m.call.dtmf'] as bool? ?? false,
transferee: json['m.call.transferee'] as bool ?? false, transferee: json['m.call.transferee'] as bool? ?? false,
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
if (transferee != null) 'm.call.transferee': transferee, if (transferee != null) 'm.call.transferee': transferee,
@ -88,11 +105,14 @@ class SDPStreamPurpose {
bool audio_muted; bool audio_muted;
bool video_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<String, dynamic> json) => factory SDPStreamPurpose.fromJson(Map<String, dynamic> json) =>
SDPStreamPurpose( SDPStreamPurpose(
audio_muted: json['audio_muted'] as bool ?? false, audio_muted: json['audio_muted'] as bool? ?? false,
video_muted: json['video_muted'] as bool ?? false, video_muted: json['video_muted'] as bool? ?? false,
purpose: json['purpose'] as String, purpose: json['purpose'] as String,
); );
@ -122,15 +142,15 @@ class SDPStreamMetadata {
/// MSC3086: Asserted identity on VoIP calls /// MSC3086: Asserted identity on VoIP calls
/// https://github.com/matrix-org/matrix-doc/pull/3086 /// https://github.com/matrix-org/matrix-doc/pull/3086
class AssertedIdentity { class AssertedIdentity {
String id; String? id;
String displayName; String? displayName;
String avatarUrl; String? avatarUrl;
AssertedIdentity({this.id, this.displayName, this.avatarUrl}); AssertedIdentity({this.id, this.displayName, this.avatarUrl});
factory AssertedIdentity.fromJson(Map<String, dynamic> json) => factory AssertedIdentity.fromJson(Map<String, dynamic> json) =>
AssertedIdentity( AssertedIdentity(
displayName: json['display_name'] as String, displayName: json['display_name'] as String?,
id: json['id'] as String, id: json['id'] as String?,
avatarUrl: json['avatar_url'] as String, avatarUrl: json['avatar_url'] as String?,
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
if (displayName != null) 'display_name': displayName, if (displayName != null) 'display_name': displayName,