refactor: Make markedUnread null safe

This commit is contained in:
Christian Pauly 2021-08-19 09:37:29 +02:00
parent 1fd40dd186
commit f311ca62e0
1 changed files with 7 additions and 17 deletions

View File

@ -1,4 +1,3 @@
// @dart=2.9
/* /*
* Famedly Matrix SDK * Famedly Matrix SDK
* Copyright (C) 2019, 2020, 2021 Famedly GmbH * Copyright (C) 2019, 2020, 2021 Famedly GmbH
@ -17,28 +16,19 @@
* 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 'package:matrix_api_lite/src/utils/try_get_map_extension.dart';
mixin EventType { mixin EventType {
static const String markedUnread = 'com.famedly.marked_unread'; static const String markedUnread = 'com.famedly.marked_unread';
} }
class MarkedUnread { class MarkedUnread {
bool unread; final bool unread;
MarkedUnread(this.unread); const MarkedUnread(this.unread);
MarkedUnread.fromJson(Map<String, dynamic> json) { MarkedUnread.fromJson(Map<String, dynamic> json)
if (!(json['unread'] is bool)) { : unread = json.tryGet<bool>('unread') ?? false;
unread = false;
} else {
unread = json['unread'];
}
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() => {'unread': unread};
final data = <String, dynamic>{};
if (unread != null) {
data['unread'] = unread;
}
return data;
}
} }