ignore invalid account data
This commit is contained in:
parent
3754bc2feb
commit
401b527714
2 changed files with 13 additions and 22 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import "dart:convert";
|
||||
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
|
||||
|
|
@ -9,11 +10,16 @@ class AccountDataController extends Notifier<AccountData> {
|
|||
AccountData build() => .new();
|
||||
|
||||
void update(IMap<String, IMap<String, dynamic>> newAccountData) =>
|
||||
state = .fromJson({
|
||||
...json.decode(json.encode(state.toJson())),
|
||||
...newAccountData
|
||||
.map((key, value) => MapEntry(key, value["content"]))
|
||||
.unlock,
|
||||
state = newAccountData.entries.fold(state, (data, entry) {
|
||||
try {
|
||||
return .fromJson({
|
||||
...json.decode(json.encode(data.toJson())),
|
||||
entry.key: entry.value["content"],
|
||||
});
|
||||
} catch (error) {
|
||||
debugPrint("Ignoring invalid ${entry.key} account data: $error");
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
||||
static final provider = NotifierProvider<AccountDataController, AccountData>(
|
||||
|
|
|
|||
|
|
@ -18,15 +18,9 @@ class const AccountData({
|
|||
final RecentEmojiData recentEmoji = const RecentEmojiData(),
|
||||
|
||||
/// Room image packs the user has enabled everywhere
|
||||
@JsonKey(
|
||||
name: AccountData.imagePackRoomsKey,
|
||||
fromJson: ImagePackRooms.tryFromJson,
|
||||
)
|
||||
@JsonKey(name: AccountData.imagePackRoomsKey)
|
||||
final ImagePackRooms? imagePackRooms,
|
||||
@JsonKey(
|
||||
name: AccountData.legacyImagePackRoomsKey,
|
||||
fromJson: ImagePackRooms.tryFromJson,
|
||||
)
|
||||
@JsonKey(name: AccountData.legacyImagePackRoomsKey)
|
||||
final ImagePackRooms? legacyImagePackRooms,
|
||||
}) with _$AccountData {
|
||||
static const invitePermissionConfigKey = "m.invite_permission_config";
|
||||
|
|
@ -59,15 +53,6 @@ class const ImagePackRooms({
|
|||
/// empty) object
|
||||
final IMap<String, IMap<String, Map<String, dynamic>>> rooms = const .empty(),
|
||||
}) with _$ImagePackRooms {
|
||||
static ImagePackRooms? tryFromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return null;
|
||||
try {
|
||||
return .fromJson(json);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object?> toJson() => _$ImagePackRoomsToJson(this);
|
||||
|
||||
factory ImagePackRooms.fromJson(Map<String, Object?> json) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue