From b625199c47eded8bed29ec97b2d07dfa77021b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 18 Dec 2016 23:08:54 +0100 Subject: [PATCH] Allow for a no limit option on restore_timeout --- gajim/chat_control.py | 10 ++-------- gajim/common/logger.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gajim/chat_control.py b/gajim/chat_control.py index 2d4dbe110..63feb5141 100644 --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -1411,12 +1411,6 @@ class ChatControl(ChatControlBase): if gajim.jid_is_transport(jid): return - # How many lines to restore and when to time them out - restore_how_many = gajim.config.get('restore_lines') - if restore_how_many <= 0: - return - timeout = gajim.config.get('restore_timeout') # in minutes - # number of messages that are in queue and are already logged, we want # to avoid duplication pending_how_many = len(gajim.events.get_events(self.account, jid, @@ -1425,8 +1419,8 @@ class ChatControl(ChatControlBase): pending_how_many += len(gajim.events.get_events(self.account, self.contact.get_full_jid(), ['chat', 'pm'])) - rows = gajim.logger.get_last_conversation_lines(jid, restore_how_many, - pending_how_many, timeout, self.account) + rows = gajim.logger.get_last_conversation_lines( + jid, pending_how_many, self.account) local_old_kind = None self.conv_textview.just_cleared = True diff --git a/gajim/common/logger.py b/gajim/common/logger.py index 6aba09f06..49ee9c856 100644 --- a/gajim/common/logger.py +++ b/gajim/common/logger.py @@ -582,8 +582,7 @@ class Logger: exceptions.PysqliteOperationalError) as error: self.dispatch('DB_ERROR', error) - def get_last_conversation_lines(self, jid, restore_how_many_rows, - pending_how_many, timeout, account): + def get_last_conversation_lines(self, jid, pending_how_many, account): """ Accept how many rows to restore and when to time them out (in minutes) (mark them as too old) and number of messages that are in queue and are @@ -598,8 +597,16 @@ class Logger: return [] where_sql, jid_tuple = self._build_contact_where(account, jid) + # How many lines to restore and when to time them out + restore_how_many = gajim.config.get('restore_lines') + if restore_how_many <= 0: + return [] + timeout = gajim.config.get('restore_timeout') # in minutes + now = int(float(time.time())) - timed_out = now - (timeout * 60) # before that they are too old + if timeout > 0: + timeout = now - (timeout * 60) # before that they are too old + # so if we ask last 5 lines and we have 2 pending we get # 3 - 8 (we avoid the last 2 lines but we still return 5 asked) try: @@ -609,8 +616,8 @@ class Logger: ORDER BY time DESC LIMIT %d OFFSET %d ''' % (where_sql, KindConstant.SINGLE_MSG_RECV, KindConstant.CHAT_MSG_RECV, KindConstant.SINGLE_MSG_SENT, - KindConstant.CHAT_MSG_SENT, KindConstant.ERROR, timed_out, - restore_how_many_rows, pending_how_many), jid_tuple) + KindConstant.CHAT_MSG_SENT, KindConstant.ERROR, timeout, + restore_how_many, pending_how_many), jid_tuple) results = self.cur.fetchall() messages = []