Philipp Hörist pushed to branch master at gajim / gajim
Commits: 50f2fa49 by Daniel Brötzmann at 2020-09-20T08:11:02+02:00 Add option to remove old chat history
- - - - -
3 changed files:
- gajim/common/setting_values.py - gajim/common/storage/archive.py - gajim/gtk/accounts.py
Changes:
===================================== gajim/common/setting_values.py ===================================== @@ -251,9 +251,10 @@ ACCOUNT_SETTINGS = { 'ft_send_local_ips': True, 'opened_chat_controls': '', 'recent_groupchats': '', - 'filetransfer_preference' : 'httpupload', + 'filetransfer_preference': 'httpupload', 'send_chatstate_default': 'composing_only', 'gc_send_chatstate_default': 'composing_only', + 'chat_history_max_age': -1, },
'contact': {
===================================== gajim/common/storage/archive.py ===================================== @@ -112,6 +112,7 @@ class MessageArchiveStorage(SqliteStorage): self._con.create_function("get_timeout", 0, self._get_timeout)
self._get_jid_ids_from_db() + self._cleanup_chat_history()
def _namedtuple_factory(self, cursor, row): fields = [col[0] for col in cursor.description] @@ -975,3 +976,22 @@ class MessageArchiveStorage(SqliteStorage): self._con.execute(sql, (jid_id,)) log.info('Reset message archive info: %s', jid) self._delayed_commit() + + def _cleanup_chat_history(self): + """ + Remove messages from account where messages are older than max_age + """ + for account in app.settings.get_accounts(): + max_age = app.settings.get_account_setting( + account, 'chat_history_max_age') + if max_age == -1: + continue + account_id = self.get_account_id(account) + now = time.time() + point_in_time = now - int(max_age) + + sql = 'DELETE FROM logs WHERE account_id = ? AND time < ?' + + cursor = self._con.execute(sql, (account_id, point_in_time)) + self._delayed_commit() + log.info('Removed %s old messages for %s', cursor.rowcount, account)
===================================== gajim/gtk/accounts.py ===================================== @@ -654,6 +654,17 @@ class PrivacyPage(GenericSettingPage): name = 'privacy'
def __init__(self, account): + self._account = account + + history_max_age = { + -1: _('Forever'), + 86400: _('1 Day'), + 604800: _('1 Week'), + 2629743: _('1 Month'), + 7889229: _('3 Months'), + 15778458: _('6 Months'), + 31556926: _('1 Year'), + }
chatstate_entries = { 'all': _('Enabled'), @@ -691,7 +702,7 @@ class PrivacyPage(GenericSettingPage): 'send_chatstate_default', desc=_('Default for chats'), props={'entries': chatstate_entries, - 'button-text':_('Reset'), + 'button-text': _('Reset'), 'button-tooltip': _('Reset all chats to the ' 'current default value'), 'button-style': 'destructive-action', @@ -703,13 +714,19 @@ class PrivacyPage(GenericSettingPage): 'gc_send_chatstate_default', desc=_('Default for group chats'), props={'entries': chatstate_entries, - 'button-text':_('Reset'), + 'button-text': _('Reset'), 'button-tooltip': _('Reset all group chats to the ' 'current default value'), 'button-style': 'destructive-action', 'button-callback': self._reset_gc_send_chatstate}),
- ] + Setting(SettingKind.POPOVER, + _('Keep Chat History'), + SettingType.ACCOUNT_CONFIG, + 'chat_history_max_age', + props={'entries': history_max_age}, + desc=_('How long Gajim should keep your chat history')), + ] GenericSettingPage.__init__(self, account, settings)
@staticmethod
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/50f2fa49017c7ac1c39fb61a4a1616fd5...