Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
50f2fa49
by Daniel Brötzmann at 2020-09-20T08:11:02+02:00
3 changed files:
Changes:
| ... | ... | @@ -251,9 +251,10 @@ ACCOUNT_SETTINGS = { |
| 251 | 251 |
'ft_send_local_ips': True,
|
| 252 | 252 |
'opened_chat_controls': '',
|
| 253 | 253 |
'recent_groupchats': '',
|
| 254 |
- 'filetransfer_preference' : 'httpupload',
|
|
| 254 |
+ 'filetransfer_preference': 'httpupload',
|
|
| 255 | 255 |
'send_chatstate_default': 'composing_only',
|
| 256 | 256 |
'gc_send_chatstate_default': 'composing_only',
|
| 257 |
+ 'chat_history_max_age': -1,
|
|
| 257 | 258 |
},
|
| 258 | 259 |
|
| 259 | 260 |
'contact': {
|
| ... | ... | @@ -112,6 +112,7 @@ class MessageArchiveStorage(SqliteStorage): |
| 112 | 112 |
self._con.create_function("get_timeout", 0, self._get_timeout)
|
| 113 | 113 |
|
| 114 | 114 |
self._get_jid_ids_from_db()
|
| 115 |
+ self._cleanup_chat_history()
|
|
| 115 | 116 |
|
| 116 | 117 |
def _namedtuple_factory(self, cursor, row):
|
| 117 | 118 |
fields = [col[0] for col in cursor.description]
|
| ... | ... | @@ -975,3 +976,22 @@ class MessageArchiveStorage(SqliteStorage): |
| 975 | 976 |
self._con.execute(sql, (jid_id,))
|
| 976 | 977 |
log.info('Reset message archive info: %s', jid)
|
| 977 | 978 |
self._delayed_commit()
|
| 979 |
+ |
|
| 980 |
+ def _cleanup_chat_history(self):
|
|
| 981 |
+ """
|
|
| 982 |
+ Remove messages from account where messages are older than max_age
|
|
| 983 |
+ """
|
|
| 984 |
+ for account in app.settings.get_accounts():
|
|
| 985 |
+ max_age = app.settings.get_account_setting(
|
|
| 986 |
+ account, 'chat_history_max_age')
|
|
| 987 |
+ if max_age == -1:
|
|
| 988 |
+ continue
|
|
| 989 |
+ account_id = self.get_account_id(account)
|
|
| 990 |
+ now = time.time()
|
|
| 991 |
+ point_in_time = now - int(max_age)
|
|
| 992 |
+ |
|
| 993 |
+ sql = 'DELETE FROM logs WHERE account_id = ? AND time < ?'
|
|
| 994 |
+ |
|
| 995 |
+ cursor = self._con.execute(sql, (account_id, point_in_time))
|
|
| 996 |
+ self._delayed_commit()
|
|
| 997 |
+ log.info('Removed %s old messages for %s', cursor.rowcount, account)
|
| ... | ... | @@ -654,6 +654,17 @@ class PrivacyPage(GenericSettingPage): |
| 654 | 654 |
name = 'privacy'
|
| 655 | 655 |
|
| 656 | 656 |
def __init__(self, account):
|
| 657 |
+ self._account = account
|
|
| 658 |
+ |
|
| 659 |
+ history_max_age = {
|
|
| 660 |
+ -1: _('Forever'),
|
|
| 661 |
+ 86400: _('1 Day'),
|
|
| 662 |
+ 604800: _('1 Week'),
|
|
| 663 |
+ 2629743: _('1 Month'),
|
|
| 664 |
+ 7889229: _('3 Months'),
|
|
| 665 |
+ 15778458: _('6 Months'),
|
|
| 666 |
+ 31556926: _('1 Year'),
|
|
| 667 |
+ }
|
|
| 657 | 668 |
|
| 658 | 669 |
chatstate_entries = {
|
| 659 | 670 |
'all': _('Enabled'),
|
| ... | ... | @@ -691,7 +702,7 @@ class PrivacyPage(GenericSettingPage): |
| 691 | 702 |
'send_chatstate_default',
|
| 692 | 703 |
desc=_('Default for chats'),
|
| 693 | 704 |
props={'entries': chatstate_entries,
|
| 694 |
- 'button-text':_('Reset'),
|
|
| 705 |
+ 'button-text': _('Reset'),
|
|
| 695 | 706 |
'button-tooltip': _('Reset all chats to the '
|
| 696 | 707 |
'current default value'),
|
| 697 | 708 |
'button-style': 'destructive-action',
|
| ... | ... | @@ -703,13 +714,19 @@ class PrivacyPage(GenericSettingPage): |
| 703 | 714 |
'gc_send_chatstate_default',
|
| 704 | 715 |
desc=_('Default for group chats'),
|
| 705 | 716 |
props={'entries': chatstate_entries,
|
| 706 |
- 'button-text':_('Reset'),
|
|
| 717 |
+ 'button-text': _('Reset'),
|
|
| 707 | 718 |
'button-tooltip': _('Reset all group chats to the '
|
| 708 | 719 |
'current default value'),
|
| 709 | 720 |
'button-style': 'destructive-action',
|
| 710 | 721 |
'button-callback': self._reset_gc_send_chatstate}),
|
| 711 | 722 |
|
| 712 |
- ]
|
|
| 723 |
+ Setting(SettingKind.POPOVER,
|
|
| 724 |
+ _('Keep Chat History'),
|
|
| 725 |
+ SettingType.ACCOUNT_CONFIG,
|
|
| 726 |
+ 'chat_history_max_age',
|
|
| 727 |
+ props={'entries': history_max_age},
|
|
| 728 |
+ desc=_('How long Gajim should keep your chat history')),
|
|
| 729 |
+ ]
|
|
| 713 | 730 |
GenericSettingPage.__init__(self, account, settings)
|
| 714 | 731 |
|
| 715 | 732 |
@staticmethod
|