Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/common/modules/contacts.py
    ... ... @@ -37,6 +37,8 @@
    37 37
     from gajim.common import types
    
    38 38
     from gajim.common.const import PresenceShowExt
    
    39 39
     from gajim.common.const import SimpleClientState
    
    40
    +from gajim.common.setting_values import BoolContactSettings
    
    41
    +from gajim.common.setting_values import StringContactSettings
    
    40 42
     from gajim.common.setting_values import BoolGroupChatSettings
    
    41 43
     from gajim.common.setting_values import IntGroupChatSettings
    
    42 44
     from gajim.common.setting_values import StringGroupChatSettings
    
    ... ... @@ -52,8 +54,26 @@
    52 54
     
    
    53 55
     class ContactSettings:
    
    54 56
         def __init__(self, account: str, jid: JID) -> None:
    
    55
    -        self.get = partial(app.settings.get_contact_setting, account, jid)
    
    56
    -        self.set = partial(app.settings.set_contact_setting, account, jid)
    
    57
    +        self._account = account
    
    58
    +        self._jid = jid
    
    59
    +
    
    60
    +    @overload
    
    61
    +    def get(self, setting: StringContactSettings) -> str: ...  # noqa: E704
    
    62
    +    @overload
    
    63
    +    def get(self, setting: BoolContactSettings) -> bool: ...  # noqa: E704
    
    64
    +
    
    65
    +    def get(self, setting: Any) -> Any:
    
    66
    +        return app.settings.get_contact_setting(
    
    67
    +            self._account, self._jid, setting)
    
    68
    +
    
    69
    +    @overload
    
    70
    +    def set(self, setting: StringContactSettings, value: str) -> None: ...  # noqa: E501, E704
    
    71
    +    @overload
    
    72
    +    def set(self, setting: BoolContactSettings, value: bool) -> None: ...  # noqa: E501, E704
    
    73
    +
    
    74
    +    def set(self, setting: Any, value: Any) -> None:
    
    75
    +        app.settings.set_contact_setting(
    
    76
    +            self._account, self._jid, setting, value)
    
    57 77
     
    
    58 78
     
    
    59 79
     class GroupChatSettings:
    

  • gajim/common/setting_values.py
    ... ... @@ -405,6 +405,23 @@ class _ACCOUNT_DEFAULT:
    405 405
     
    
    406 406
     AllGroupChatSettingsT = Union[str, int, bool]
    
    407 407
     
    
    408
    +
    
    409
    +BoolContactSettings = Literal[
    
    410
    +    'send_marker',
    
    411
    +]
    
    412
    +
    
    413
    +StringContactSettings = Literal[
    
    414
    +    'encryption',
    
    415
    +    'speller_language',
    
    416
    +    'send_chatstate',
    
    417
    +]
    
    418
    +
    
    419
    +AllContactSettings = Literal[BoolContactSettings,
    
    420
    +                             StringContactSettings]
    
    421
    +
    
    422
    +AllContactSettingsT = Union[str, bool]
    
    423
    +
    
    424
    +
    
    408 425
     ACCOUNT_SETTINGS = {
    
    409 426
         'account': {
    
    410 427
             'account_color': 'rgb(85, 85, 85)',
    

  • gajim/common/settings.py
    ... ... @@ -45,6 +45,10 @@
    45 45
     from gajim.common.storage.base import Encoder
    
    46 46
     from gajim.common.storage.base import json_decoder
    
    47 47
     from gajim.common.setting_values import APP_SETTINGS
    
    48
    +from gajim.common.setting_values import AllContactSettings
    
    49
    +from gajim.common.setting_values import AllContactSettingsT
    
    50
    +from gajim.common.setting_values import BoolContactSettings
    
    51
    +from gajim.common.setting_values import StringContactSettings
    
    48 52
     from gajim.common.setting_values import AllGroupChatSettings
    
    49 53
     from gajim.common.setting_values import AllGroupChatSettingsT
    
    50 54
     from gajim.common.setting_values import BoolGroupChatSettings
    
    ... ... @@ -923,10 +927,27 @@ def set_group_chat_settings(self,
    923 927
                             continue
    
    924 928
                     self.set_group_chat_setting(account, jid, setting, value)
    
    925 929
     
    
    930
    +    @overload
    
    926 931
         def get_contact_setting(self,
    
    927 932
                                 account: str,
    
    928 933
                                 jid: JID,
    
    929
    -                            setting: str) -> SETTING_TYPE:
    
    934
    +                            setting: BoolContactSettings
    
    935
    +                            ) -> bool:
    
    936
    +        ...
    
    937
    +
    
    938
    +    @overload
    
    939
    +    def get_contact_setting(self,
    
    940
    +                            account: str,
    
    941
    +                            jid: JID,
    
    942
    +                            setting: StringContactSettings
    
    943
    +                            ) -> str:
    
    944
    +        ...
    
    945
    +
    
    946
    +    def get_contact_setting(self,
    
    947
    +                            account: str,
    
    948
    +                            jid: JID,
    
    949
    +                            setting: AllContactSettings
    
    950
    +                            ) -> AllContactSettingsT:
    
    930 951
     
    
    931 952
             if account not in self._account_settings:
    
    932 953
                 raise ValueError(f'Account missing: {account}')
    
    ... ... @@ -946,11 +967,27 @@ def get_contact_setting(self,
    946 967
     
    
    947 968
                 return default
    
    948 969
     
    
    970
    +    @overload
    
    949 971
         def set_contact_setting(self,
    
    950 972
                                 account: str,
    
    951 973
                                 jid: JID,
    
    952
    -                            setting: str,
    
    953
    -                            value: SETTING_TYPE) -> None:
    
    974
    +                            setting: StringContactSettings,
    
    975
    +                            value: str) -> None:
    
    976
    +        ...
    
    977
    +
    
    978
    +    @overload
    
    979
    +    def set_contact_setting(self,
    
    980
    +                            account: str,
    
    981
    +                            jid: JID,
    
    982
    +                            setting: BoolContactSettings,
    
    983
    +                            value: bool) -> None:
    
    984
    +        ...
    
    985
    +
    
    986
    +    def set_contact_setting(self,
    
    987
    +                            account: str,
    
    988
    +                            jid: JID,
    
    989
    +                            setting: AllContactSettings,
    
    990
    +                            value: AllContactSettingsT) -> None:
    
    954 991
     
    
    955 992
             if account not in self._account_settings:
    
    956 993
                 raise ValueError(f'Account missing: {account}')
    
    ... ... @@ -992,7 +1029,7 @@ def set_contact_setting(self,
    992 1029
     
    
    993 1030
         def set_contact_settings(self,
    
    994 1031
                                  setting: str,
    
    995
    -                             value: SETTING_TYPE) -> None:
    
    1032
    +                             value: AllContactSettings) -> None:
    
    996 1033
     
    
    997 1034
             for account, acc_settings in self._account_settings.items():
    
    998 1035
                 for jid in acc_settings['contact']: