From 7c40f72f55f98bb283743a6135753c53847a0217 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sat, 18 Sep 2021 15:41:56 +0200 Subject: [PATCH] Client.setAccountBundle && Client.removeFromAccountBundle && Client.sendPrefix --- lib/utils/account_bundles.dart | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/utils/account_bundles.dart b/lib/utils/account_bundles.dart index 93006acc..83670695 100644 --- a/lib/utils/account_bundles.dart +++ b/lib/utils/account_bundles.dart @@ -61,4 +61,37 @@ extension AccountBundlesExtension on Client { } return ret; } + + Future 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 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; + } }