refactor: Update to Dart 3.10 with . shorthands

This commit is contained in:
Christian Kußowski 2025-11-30 12:54:06 +01:00
commit 1ea649f01e
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
167 changed files with 3351 additions and 3912 deletions

View file

@ -7,9 +7,9 @@ class AccountBundles {
AccountBundles({this.prefix, this.bundles});
AccountBundles.fromJson(Map<String, dynamic> json)
: prefix = json.tryGet<String>('prefix'),
bundles = json['bundles'] is List
? json['bundles']
: prefix = json.tryGet<String>('prefix'),
bundles = json['bundles'] is List
? json['bundles']
.map((b) {
try {
return AccountBundle.fromJson(b);
@ -19,13 +19,12 @@ class AccountBundles {
})
.whereType<AccountBundle>()
.toList()
: null;
: null;
Map<String, dynamic> toJson() => {
if (prefix != null) 'prefix': prefix,
if (bundles != null)
'bundles': bundles!.map((v) => v.toJson()).toList(),
};
if (prefix != null) 'prefix': prefix,
if (bundles != null) 'bundles': bundles!.map((v) => v.toJson()).toList(),
};
}
class AccountBundle {
@ -35,13 +34,13 @@ class AccountBundle {
AccountBundle({this.name, this.priority});
AccountBundle.fromJson(Map<String, dynamic> json)
: name = json.tryGet<String>('name'),
priority = json.tryGet<int>('priority');
: name = json.tryGet<String>('name'),
priority = json.tryGet<int>('priority');
Map<String, dynamic> toJson() => <String, dynamic>{
if (name != null) 'name': name,
if (priority != null) 'priority': priority,
};
if (name != null) 'name': name,
if (priority != null) 'priority': priority,
};
}
const accountBundlesType = 'im.fluffychat.account_bundles';
@ -50,24 +49,21 @@ extension AccountBundlesExtension on Client {
List<AccountBundle> get accountBundles {
List<AccountBundle>? ret;
if (accountData.containsKey(accountBundlesType)) {
ret = AccountBundles.fromJson(accountData[accountBundlesType]!.content)
.bundles;
ret = AccountBundles.fromJson(
accountData[accountBundlesType]!.content,
).bundles;
}
ret ??= [];
if (ret.isEmpty) {
ret.add(
AccountBundle(
name: userID,
priority: 0,
),
);
ret.add(AccountBundle(name: userID, priority: 0));
}
return ret;
}
Future<void> setAccountBundle(String name, [int? priority]) async {
final data =
AccountBundles.fromJson(accountData[accountBundlesType]?.content ?? {});
final data = AccountBundles.fromJson(
accountData[accountBundlesType]?.content ?? {},
);
var foundBundle = false;
final bundles = data.bundles ??= [];
for (final bundle in bundles) {
@ -87,16 +83,18 @@ extension AccountBundlesExtension on Client {
if (!accountData.containsKey(accountBundlesType)) {
return; // nothing to do
}
final data =
AccountBundles.fromJson(accountData[accountBundlesType]!.content);
final data = AccountBundles.fromJson(
accountData[accountBundlesType]!.content,
);
if (data.bundles == null) return;
data.bundles!.removeWhere((b) => b.name == name);
await setAccountData(userID!, accountBundlesType, data.toJson());
}
String get sendPrefix {
final data =
AccountBundles.fromJson(accountData[accountBundlesType]?.content ?? {});
final data = AccountBundles.fromJson(
accountData[accountBundlesType]?.content ?? {},
);
return data.prefix!;
}
}