Philipp Hörist pushed to branch master at gajim / gajim
Commits: de206c40 by lovetox at 2020-11-18T22:58:24+01:00 Settings: Simplify context dependent settings
- - - - -
8 changed files:
- gajim/common/contacts.py - gajim/common/modules/chat_markers.py - gajim/common/modules/mam.py - gajim/common/settings.py - gajim/groupchat_control.py - gajim/gtk/const.py - gajim/gtk/groupchat_settings.py - gajim/gtk/settings.py
Changes:
===================================== gajim/common/contacts.py ===================================== @@ -271,14 +271,8 @@ def can_notify(self): if not self.is_groupchat: raise ValueError
- disco_info = app.storage.cache.get_last_disco_info(self.jid) - - context = 'public' - if disco_info is not None and disco_info.muc_is_members_only: - context = 'private' - all_ = app.settings.get('notify_on_all_muc_messages') - room = self.settings.get('notify_on_all_messages', context=context) + room = self.settings.get('notify_on_all_messages') return all_ or room
===================================== gajim/common/modules/chat_markers.py ===================================== @@ -91,14 +91,8 @@ def _send_marker(self, contact, marker, id_, type_): jid = app.get_jid_without_resource(contact.jid)
if type_ in ('gc', 'pm'): - disco_info = app.storage.cache.get_last_disco_info(jid) - - context = 'public' - if disco_info is not None and disco_info.muc_is_members_only: - context = 'private' - if not app.settings.get_group_chat_setting( - self._account, jid, 'send_marker', context=context): + self._account, jid, 'send_marker'): return else: if not app.settings.get_contact_setting(
===================================== gajim/common/modules/mam.py ===================================== @@ -374,16 +374,9 @@ def request_archive_on_signin(self): def request_archive_on_muc_join(self, jid): _task = yield
- disco_info = app.storage.cache.get_last_disco_info(jid) - - context = 'public' - if disco_info is not None and disco_info.muc_is_members_only: - context = 'private' - threshold = app.settings.get_group_chat_setting(self._account, jid, - 'sync_threshold', - context=context) + 'sync_threshold') self._log.info('Threshold for %s: %s', jid, threshold)
if threshold == SyncThreshold.NO_SYNC:
===================================== gajim/common/settings.py ===================================== @@ -601,8 +601,7 @@ def set_account_setting(self, def get_group_chat_setting(self, account: str, jid: str, - setting: str, - context: str = None) -> SETTING_TYPE: + setting: str) -> SETTING_TYPE:
if account not in self._account_settings: raise ValueError(f'Account missing: {account}') @@ -613,17 +612,26 @@ def get_group_chat_setting(self, try: return self._account_settings[account]['group_chat'][jid][setting] except KeyError: + + context = get_muc_context(jid) + if context is None: + # If there is no disco info available + # to determine the context assume public + log.warning('Unable to determine context for: %s', jid) + context = 'public' + default = ACCOUNT_SETTINGS['group_chat'][setting] if default is HAS_APP_DEFAULT: - if context is not None: - return self.get_app_setting( - f'gc_{setting}_{context}_default') + context_default_setting = f'gc_{setting}_{context}_default' + if context_default_setting in APP_SETTINGS: + return self.get_app_setting(context_default_setting) return self.get_app_setting(f'gc_{setting}_default')
if default is HAS_ACCOUNT_DEFAULT: - if context is not None: - return self.get_account_setting( - account, f'gc_{setting}_{context}_default') + context_default_setting = f'gc_{setting}_{context}_default' + if context_default_setting in ACCOUNT_SETTINGS['account']: + return self.get_account_setting(account, + context_default_setting) return self.get_account_setting(account, f'gc_{setting}_default')
@@ -633,8 +641,7 @@ def set_group_chat_setting(self, account: str, jid: str, setting: str, - value: SETTING_TYPE, - context: str = None) -> None: + value: SETTING_TYPE) -> None:
if account not in self._account_settings: raise ValueError(f'Account missing: {account}') @@ -645,14 +652,22 @@ def set_group_chat_setting(self, default = ACCOUNT_SETTINGS['group_chat'][setting] if default in (HAS_APP_DEFAULT, HAS_ACCOUNT_DEFAULT):
+ context = get_muc_context(jid) + if context is None: + # If there is no disco info available + # to determine the context assume public + log.warning('Unable to determine context for: %s', jid) + context = 'public' + default_store = APP_SETTINGS if default is HAS_ACCOUNT_DEFAULT: default_store = ACCOUNT_SETTINGS['account']
- if context is None: - default = default_store[f'gc_{setting}_default'] + context_default_setting = f'gc_{setting}_{context}_default' + if context_default_setting in default_store: + default = default_store[context_default_setting] else: - default = default_store[f'gc_{setting}_{context}_default'] + default = default_store[f'gc_{setting}_default']
if not isinstance(value, type(default)) and value is not None: raise TypeError(f'Invalid type for {setting}: ' @@ -687,8 +702,7 @@ def set_group_chat_settings(self, if context is not None: if get_muc_context(jid) != context: continue - self.set_group_chat_setting( - account, jid, setting, value, context) + self.set_group_chat_setting(account, jid, setting, value)
def get_contact_setting(self, account: str,
===================================== gajim/groupchat_control.py ===================================== @@ -178,7 +178,7 @@ def __init__(self, parent_win, contact, muc_data, acct):
# Groupchat settings self._groupchat_settings_box = GroupChatSettings( - self.account, self.room_jid, self.context) + self.account, self.room_jid) self.xml.settings_scrolled_box.add(self._groupchat_settings_box)
# Groupchat invite @@ -273,13 +273,6 @@ def room_name(self): def disco_info(self): return app.storage.cache.get_last_disco_info(self.contact.jid)
- @property - def context(self): - disco_info = self.disco_info - if disco_info is None or not self.disco_info.muc_is_members_only: - return 'public' - return 'private' - def add_actions(self): super().add_actions() actions = [
===================================== gajim/gtk/const.py ===================================== @@ -22,7 +22,7 @@ Filter = namedtuple('Filter', 'name pattern default')
Setting = namedtuple('Setting', 'kind label type value name callback data desc ' - 'bind inverted enabled_func context props') + 'bind inverted enabled_func props') Setting.__new__.__defaults__ = (None,) * len(Setting._fields) # type: ignore
@unique
===================================== gajim/gtk/groupchat_settings.py ===================================== @@ -24,7 +24,7 @@
class GroupChatSettings(SettingsBox): - def __init__(self, account, jid, context): + def __init__(self, account, jid): SettingsBox.__init__(self, account, jid)
self.get_style_context().add_class('settings-border') @@ -52,8 +52,7 @@ def __init__(self, account, jid, context): Setting(SettingKind.SWITCH, _('Notify on all Messages'), SettingType.GROUP_CHAT, - 'notify_on_all_messages', - context=context), + 'notify_on_all_messages'),
Setting(SettingKind.SWITCH, _('Minimize on Close'), @@ -75,14 +74,12 @@ def __init__(self, account, jid, context): _('Send Chat Markers'), SettingType.GROUP_CHAT, 'send_marker', - context=context, desc=_('Let others know if you read up to this point')),
Setting(SettingKind.POPOVER, _('Sync Threshold'), SettingType.GROUP_CHAT, 'sync_threshold', - context=context, props={'entries': THRESHOLD_OPTIONS}),
]
===================================== gajim/gtk/settings.py ===================================== @@ -148,8 +148,7 @@ def __init__(self, desc, bind, inverted, - enabled_func, - context): + enabled_func):
Gtk.ListBoxRow.__init__(self) self._grid = Gtk.Grid() @@ -163,7 +162,6 @@ def __init__(self, self.label = label self.account = account self.jid = jid - self.context = context self.name = name self.bind = bind self.inverted = inverted @@ -252,11 +250,10 @@ def get_value(self): return self.__get_value(self.type_, self.value, self.account, - self.jid, - self.context) + self.jid)
@staticmethod - def __get_value(type_, value, account, jid, context): + def __get_value(type_, value, account, jid): if value is None: return None if type_ == SettingType.VALUE: @@ -267,7 +264,7 @@ def __get_value(type_, value, account, jid, context):
if type_ == SettingType.GROUP_CHAT: return app.settings.get_group_chat_setting( - account, jid, value, context) + account, jid, value)
if type_ == SettingType.CONFIG: return app.settings.get(value) @@ -308,7 +305,7 @@ def set_value(self, state):
elif self.type_ == SettingType.GROUP_CHAT: app.settings.set_group_chat_setting( - self.account, self.jid, self.value, state, self.context) + self.account, self.jid, self.value, state)
if self.callback is not None: self.callback(state, self.data)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/de206c40cbf8e879a218cb0c3e00f074c...