Philipp Hörist pushed to branch master at gajim / gajim
Commits: a72de039 by lovetox at 2020-09-18T23:45:29+02:00 Settings: Move treshold setting from archive storage
- - - - -
9 changed files:
- gajim/common/config.py - gajim/common/const.py - gajim/common/helpers.py - gajim/common/modules/mam.py - gajim/common/setting_values.py - gajim/common/storage/archive.py - gajim/groupchat_control.py - gajim/gtk/preferences.py - gajim/gui_menu_builder.py
Changes:
===================================== gajim/common/config.py ===================================== @@ -227,7 +227,6 @@ class Config: 'use_keyring': [opt_bool, True, _('If enabled, Gajim will use the System's Keyring to store account passwords.')], 'remote_commands': [opt_bool, False, _('If enabled, Gajim will execute XEP-0146 Commands.')], 'dark_theme': [opt_int, 2, _('2: System, 1: Enabled, 0: Disabled')], - 'threshold_options': [opt_str, '1, 2, 4, 10, 0', _('Options in days which can be chosen in the sync threshold menu'), True], 'public_room_sync_threshold': [opt_int, 1, _('Maximum history in days we request from a public group chat archive. 0: As much as possible.')], 'private_room_sync_threshold': [opt_int, 0, _('Maximum history in days we request from a private group chat archive. 0: As much as possible.')], 'show_subject_on_join': [opt_bool, True, _('If enabled, Gajim shows the group chat subject in the chat window when joining.')],
===================================== gajim/common/const.py ===================================== @@ -161,6 +161,7 @@ class Chatstate(IntEnum):
class SyncThreshold(IntEnum): + NO_SYNC = -1 NO_THRESHOLD = 0
def __str__(self): @@ -1085,3 +1086,13 @@ URI_SCHEMES = { 'webcal://', 'aesgcm://', } + + +THRESHOLD_OPTIONS = { + -1: _('No Sync'), + 1: _('1 Day'), + 2: _('2 Days'), + 7: _('1 Week'), + 30: _('1 Month'), + 0: _('No Threshold'), +}
===================================== gajim/common/helpers.py ===================================== @@ -897,17 +897,6 @@ def call_counter(func): return func(self) return helper
-def get_sync_threshold(jid, archive_info): - disco_info = app.storage.cache.get_last_disco_info(jid) - if archive_info is None or archive_info.sync_threshold is None: - if disco_info is not None and disco_info.muc_is_members_only: - threshold = app.settings.get('private_room_sync_threshold') - else: - threshold = app.settings.get('public_room_sync_threshold') - app.storage.archive.set_archive_infos(jid, sync_threshold=threshold) - return threshold - return archive_info.sync_threshold - def load_json(path, key=None, default=None): try: with path.open('r') as file:
===================================== gajim/common/modules/mam.py ===================================== @@ -30,7 +30,6 @@ from gajim.common.nec import NetworkIncomingEvent from gajim.common.const import ArchiveState from gajim.common.const import KindConstant from gajim.common.const import SyncThreshold -from gajim.common.helpers import get_sync_threshold from gajim.common.helpers import AdditionalDataDict from gajim.common.modules.misc import parse_oob from gajim.common.modules.misc import parse_correction @@ -302,9 +301,21 @@ class MAM(BaseModule):
def request_archive_on_muc_join(self, jid): archive = app.storage.archive.get_archive_infos(jid) - threshold = get_sync_threshold(jid, archive) + 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) self._log.info('Threshold for %s: %s', jid, threshold)
+ if threshold == SyncThreshold.NO_SYNC: + return + mam_id = None start_date = None if archive is None or archive.last_mam_id is None:
===================================== gajim/common/setting_values.py ===================================== @@ -167,9 +167,8 @@ APP_SETTINGS = { 'use_keyring': True, 'remote_commands': False, 'dark_theme': 2, - 'threshold_options': '1, 2, 4, 10, 0', - 'public_room_sync_threshold': 1, - 'private_room_sync_threshold': 0, + 'gc_sync_threshold_public_default': 1, + 'gc_sync_threshold_private_default': 0, 'show_subject_on_join': True, 'show_chatstate_in_roster': True, 'show_chatstate_in_tabs': True, @@ -275,6 +274,7 @@ ACCOUNT_SETTINGS = { 'minimize_on_close': True, 'send_chatstate': HAS_ACCOUNT_DEFAULT, 'encryption': '', + 'sync_threshold': HAS_APP_DEFAULT, }, }
@@ -449,8 +449,6 @@ ADVANCED_SETTINGS = { 'ignore_incoming_attention': _('If enabled, Gajim will ignore incoming attention requests ('wizz').'), 'remember_opened_chat_controls': _('If enabled, Gajim will reopen chat windows that were opened last time Gajim was closed.'), 'remote_commands': _('If enabled, Gajim will execute XEP-0146 Commands.'), - 'threshold_options': _('Options in days which can be chosen in the sync threshold menu'), - 'private_room_sync_threshold': _('Maximum history in days we request from a private group chat archive. 0: As much as possible.'), 'muclumbus_api_jid': '', 'muclumbus_api_http_uri': '', 'muclumbus_api_pref': _('API Preferences. Possible values: 'http', 'iq''),
===================================== gajim/common/storage/archive.py ===================================== @@ -41,7 +41,7 @@ from gajim.common.storage.base import SqliteStorage from gajim.common.storage.base import timeit
-CURRENT_USER_VERSION = 5 +CURRENT_USER_VERSION = 6
ARCHIVE_SQL_STATEMENT = ''' CREATE TABLE jids( @@ -78,7 +78,6 @@ ARCHIVE_SQL_STATEMENT = ''' last_mam_id TEXT, oldest_mam_timestamp TEXT, last_muc_timestamp TEXT, - sync_threshold INTEGER ); CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC); CREATE INDEX idx_logs_stanza_id ON logs (stanza_id); @@ -940,14 +939,13 @@ class MessageArchiveStorage(SqliteStorage): if not exists: sql = '''INSERT INTO last_archive_message (jid_id, last_mam_id, oldest_mam_timestamp, - last_muc_timestamp, sync_threshold) - VALUES (?, ?, ?, ?, ?)''' + last_muc_timestamp) + VALUES (?, ?, ?, ?)''' self._con.execute(sql, ( jid_id, kwargs.get('last_mam_id', None), kwargs.get('oldest_mam_timestamp', None), kwargs.get('last_muc_timestamp', None), - kwargs.get('sync_threshold', None) )) else: for key, value in list(kwargs.items()):
===================================== gajim/groupchat_control.py ===================================== @@ -268,6 +268,13 @@ class GroupchatControl(ChatControlBase): 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 = [ @@ -322,12 +329,8 @@ class GroupchatControl(ChatControlBase): act.connect('change-state', self._on_send_chatstate) self.parent_win.window.add_action(act)
- context = 'public' - if self.disco_info is not None and self.disco_info.muc_is_members_only: - context = 'private' - value = self.contact.settings.get('notify_on_all_messages', - context=context) + context=self.context)
act = Gio.SimpleAction.new_stateful( 'notify-on-message-' + self.control_id, @@ -351,9 +354,8 @@ class GroupchatControl(ChatControlBase): act.connect('change-state', self._on_print_join_left) self.parent_win.window.add_action(act)
- archive_info = app.storage.archive.get_archive_infos(self.contact.jid) - threshold = helpers.get_sync_threshold(self.contact.jid, - archive_info) + threshold = self.contact.settings.get('sync_threshold', + context=self.context)
initial = GLib.Variant.new_string(str(threshold)) act = Gio.SimpleAction.new_stateful( @@ -534,9 +536,8 @@ class GroupchatControl(ChatControlBase):
# After the room has been created, reevaluate threshold if self.disco_info.has_mam: - archive_info = app.storage.archive.get_archive_infos(self.contact.jid) - threshold = helpers.get_sync_threshold(self.contact.jid, - archive_info) + threshold = self.contact.settings.get('sync_threshold', + context=self.context) win.change_action_state('choose-sync-%s' % self.control_id, GLib.Variant('s', str(threshold)))
@@ -661,7 +662,9 @@ class GroupchatControl(ChatControlBase): def _on_sync_threshold(self, action, param): threshold = param.get_string() action.set_state(param) - app.storage.archive.set_archive_infos(self.contact.jid, sync_threshold=threshold) + self.contact.settings.set('sync_threshold', + int(threshold), + context=self.context)
def _on_execute_command(self, _action, param): jid = self.room_jid
===================================== gajim/gtk/preferences.py ===================================== @@ -21,9 +21,9 @@ from gi.repository import Gdk from gajim.common import app from gajim.common import configpaths from gajim.common import helpers +from gajim.common.const import THRESHOLD_OPTIONS from gajim.common.nec import NetworkEvent from gajim.common.i18n import _ -from gajim.common.i18n import ngettext from gajim.common.helpers import open_file from gajim.common.multimedia_helpers import AudioInputManager from gajim.common.multimedia_helpers import AudioOutputManager @@ -390,16 +390,6 @@ class Chats(PreferenceBox): class GroupChats(PreferenceBox): def __init__(self, *args):
- sync_threshold = {} - options = app.settings.get('threshold_options').split(',') - days = [int(option.strip()) for option in options] - for day in days: - if day == 0: - label = _('No threshold') - else: - label = ngettext('%i day', '%i days', day, day, day) - sync_threshold[day] = label - settings = [
Setting(SettingKind.SWITCH, @@ -416,9 +406,9 @@ class GroupChats(PreferenceBox): Setting(SettingKind.POPOVER, _('Default Sync Threshold'), SettingType.CONFIG, - 'public_room_sync_threshold', + 'gc_sync_threshold_public_default', desc=_('Default for new public group chats'), - props={'entries': sync_threshold}, + props={'entries': THRESHOLD_OPTIONS}, callback=self._on_sync_threshold_changed),
Setting(SettingKind.SWITCH,
===================================== gajim/gui_menu_builder.py ===================================== @@ -22,10 +22,10 @@ from gajim.common import app from gajim.common import helpers from gajim.common.helpers import is_affiliation_change_allowed from gajim.common.helpers import is_role_change_allowed -from gajim.common.i18n import ngettext from gajim.common.i18n import _ from gajim.common.const import URIType from gajim.common.const import URIAction +from gajim.common.const import THRESHOLD_OPTIONS
from gajim.gtk.util import get_builder from gajim.gtk.const import ControlType @@ -633,15 +633,9 @@ def get_groupchat_menu(control_id, account, jid):
def build_sync_menu(): menu = Gio.Menu() - days = app.settings.get('threshold_options').split(',') - days = [int(day) for day in days] action_name = 'win.choose-sync-%s::' % control_id - for day in days: - if day == 0: - label = _('No threshold') - else: - label = ngettext('%i day', '%i days', day, day, day) - menu.append(label, '%s%s' % (action_name, day)) + for days, label in THRESHOLD_OPTIONS.items(): + menu.append(label, '%s%s' % (action_name, days)) return menu
def build_chatstate_menu():
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/a72de0396002a6d28ea25a22a4c8fc61b...