Client.setAccountBundle && Client.removeFromAccountBundle && Client.sendPrefix

This commit is contained in:
Sorunome 2021-09-18 15:41:56 +02:00
parent 1278b91eed
commit 7c40f72f55
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C

View File

@ -61,4 +61,37 @@ extension AccountBundlesExtension on Client {
}
return ret;
}
Future<void> setAccountBundle(String name, [int priority]) async {
final data = AccountBundles.fromJson(
accountData[_accountBundlesType]?.content ?? {});
var foundBundle = false;
for (final bundle in data.bundles) {
if (bundle.name == name) {
bundle.priority = priority;
foundBundle = true;
break;
}
}
if (!foundBundle) {
data.bundles.add(AccountBundle(name: name, priority: priority));
}
await setAccountData(userID, _accountBundlesType, data.toJson());
}
Future<void> removeFromAccountBundle(String name) async {
if (!accountData.containsKey(_accountBundlesType)) {
return; // nothing to do
}
final data =
AccountBundles.fromJson(accountData[_accountBundlesType].content);
data.bundles.removeWhere((b) => b.name == name);
await setAccountData(userID, _accountBundlesType, data.toJson());
}
String get sendPrefix {
final data = AccountBundles.fromJson(
accountData[_accountBundlesType]?.content ?? {});
return data.prefix;
}
}