Skip to content
Snippets Groups Projects
Commit f77737b0 authored by Daniel Brötzmann's avatar Daniel Brötzmann
Browse files

chore: Settings: Add type annotations for Contact settings

parent 646d1bf5
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,8 @@
from gajim.common import types
from gajim.common.const import PresenceShowExt
from gajim.common.const import SimpleClientState
from gajim.common.setting_values import BoolContactSettings
from gajim.common.setting_values import StringContactSettings
from gajim.common.setting_values import BoolGroupChatSettings
from gajim.common.setting_values import IntGroupChatSettings
from gajim.common.setting_values import StringGroupChatSettings
......@@ -52,8 +54,26 @@
class ContactSettings:
def __init__(self, account: str, jid: JID) -> None:
self.get = partial(app.settings.get_contact_setting, account, jid)
self.set = partial(app.settings.set_contact_setting, account, jid)
self._account = account
self._jid = jid
@overload
def get(self, setting: StringContactSettings) -> str: ... # noqa: E704
@overload
def get(self, setting: BoolContactSettings) -> bool: ... # noqa: E704
def get(self, setting: Any) -> Any:
return app.settings.get_contact_setting(
self._account, self._jid, setting)
@overload
def set(self, setting: StringContactSettings, value: str) -> None: ... # noqa: E501, E704
@overload
def set(self, setting: BoolContactSettings, value: bool) -> None: ... # noqa: E501, E704
def set(self, setting: Any, value: Any) -> None:
app.settings.set_contact_setting(
self._account, self._jid, setting, value)
class GroupChatSettings:
......
......@@ -405,6 +405,23 @@ class _ACCOUNT_DEFAULT:
AllGroupChatSettingsT = Union[str, int, bool]
BoolContactSettings = Literal[
'send_marker',
]
StringContactSettings = Literal[
'encryption',
'speller_language',
'send_chatstate',
]
AllContactSettings = Literal[BoolContactSettings,
StringContactSettings]
AllContactSettingsT = Union[str, bool]
ACCOUNT_SETTINGS = {
'account': {
'account_color': 'rgb(85, 85, 85)',
......
......@@ -45,6 +45,10 @@
from gajim.common.storage.base import Encoder
from gajim.common.storage.base import json_decoder
from gajim.common.setting_values import APP_SETTINGS
from gajim.common.setting_values import AllContactSettings
from gajim.common.setting_values import AllContactSettingsT
from gajim.common.setting_values import BoolContactSettings
from gajim.common.setting_values import StringContactSettings
from gajim.common.setting_values import AllGroupChatSettings
from gajim.common.setting_values import AllGroupChatSettingsT
from gajim.common.setting_values import BoolGroupChatSettings
......@@ -923,10 +927,27 @@ def set_group_chat_settings(self,
continue
self.set_group_chat_setting(account, jid, setting, value)
@overload
def get_contact_setting(self,
account: str,
jid: JID,
setting: str) -> SETTING_TYPE:
setting: BoolContactSettings
) -> bool:
...
@overload
def get_contact_setting(self,
account: str,
jid: JID,
setting: StringContactSettings
) -> str:
...
def get_contact_setting(self,
account: str,
jid: JID,
setting: AllContactSettings
) -> AllContactSettingsT:
if account not in self._account_settings:
raise ValueError(f'Account missing: {account}')
......@@ -946,11 +967,27 @@ def get_contact_setting(self,
return default
@overload
def set_contact_setting(self,
account: str,
jid: JID,
setting: str,
value: SETTING_TYPE) -> None:
setting: StringContactSettings,
value: str) -> None:
...
@overload
def set_contact_setting(self,
account: str,
jid: JID,
setting: BoolContactSettings,
value: bool) -> None:
...
def set_contact_setting(self,
account: str,
jid: JID,
setting: AllContactSettings,
value: AllContactSettingsT) -> None:
if account not in self._account_settings:
raise ValueError(f'Account missing: {account}')
......@@ -992,7 +1029,7 @@ def set_contact_setting(self,
def set_contact_settings(self,
setting: str,
value: SETTING_TYPE) -> None:
value: AllContactSettings) -> None:
for account, acc_settings in self._account_settings.items():
for jid in acc_settings['contact']:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment