From 60c44b23e769dab115e6be1740af00b43b5323d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 6 Nov 2023 10:50:43 +0100 Subject: new: Settings: Add method for checking if account exists --- gajim/common/settings.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gajim/common/settings.py b/gajim/common/settings.py index 063860184..105869e28 100644 --- a/gajim/common/settings.py +++ b/gajim/common/settings.py @@ -754,6 +754,9 @@ class Settings: def add_account(self, account: str) -> None: log.info('Add account: %s', account) + if account in self._account_settings: + raise ValueError('Account %s exists already' % account) + self._account_settings[account] = {'account': {}, 'contact': {}, 'group_chat': {}} @@ -775,6 +778,14 @@ class Settings: def get_accounts(self) -> list[str]: return list(self._account_settings.keys()) + def account_exists(self, jid: str) -> bool: + for account in self._account_settings: + name = self.get_account_setting(account, 'name') + hostname = self.get_account_setting(account, 'hostname') + if jid == f'{name}@{hostname}': + return True + return False + def get_active_accounts(self) -> list[str]: active: list[str] = [] for account in self._account_settings: -- cgit v1.2.3