Commit e0ba19f9 authored by nkour's avatar nkour

commit logic of func; we were returning anyways. TC is oftenly touched, so I...

commit logic of func; we were returning anyways. TC is oftenly touched, so I commit to avoid conflicts
parent 880da6fb
......@@ -892,68 +892,36 @@ def restore_conversation(self, jid):
if gajim.jid_is_transport(jid):
return # FIXME: clean up logic, make most of it a func for
# see get_last_conversation_lines
# good to review to avoid dup last line (still happens)
return # FIXME: the logic below works, but needs db so return atm
# How many lines to restore and when to time them out
restore = gajim.config.get('restore_lines')
restore_how_many = gajim.config.get('restore_lines')
timeout = gajim.config.get('restore_timeout') # in minutes
pos = 0 # position, while reading from history
size = 0 # how many lines we already retreived
lines = [] # we'll need to reverse the lines from history
count = gajim.logger.get_no_of_lines(jid)
# pos: number of messages that are in queue and are printed in log file
pos = 0
# number of messages that are in queue and are already logged
pending_how_many = 0 # we want to avoid duplication
if gajim.awaiting_events[self.account].has_key(jid):
l = gajim.awaiting_events[self.account][jid]
for event in l:
events = gajim.awaiting_events[self.account][jid]
for event in events:
if event[0] == 'chat':
pos += 1
now = time.time()
while size <= restore:
if pos == count or size > restore - 1:
# don't try to read beyond history, nor read more than required
line = gajim.logger.read_from_line_to_line(jid, count - 1 - pos, count - pos)
pos = pos + 1
pending_how_many += 1
# line is [] if log file for jid is not a file (does not exist or dir)
if line == []:
if (now - float(line[0][0])) / 60 >= time_out:
# stop looking for messages if we found something too old
if line[0][1] != 'sent' and line[0][1] != 'recv':
# we don't want to display status lines, do we?
size = size + 1
if lines != []:
rows = gajim.logger.get_last_conversation_lines(jid, restore_how_many,
pending_how_many, timeout)
print lines
for line in lines: # line[0] time, line[1] type, line[2:] the message
if line[1] == 'sent':
for row in rows: # row[0] time, row[1] has kind, row[2] the message
if row[1] in ('chat_msg_sent', 'single_msg_sent'):
kind = 'outgoing'
name = gajim.nicks[self.account]
elif line[1] == 'recv':
elif row[1] in ('single_msg_recv', 'chat_msg_recv'):
kind = 'incoming'
name = self.contacts[jid].name
tim = time.localtime(float(line[0]))
tim = time.localtime(float(row[0]))
text = ':'.join(line[2:])[:-1] #remove the latest \n
self.print_conversation_line(text, jid, kind, name, tim,
self.print_conversation_line(row[2], jid, kind, name, tim,
['small'], ['small', 'grey'], ['small', 'grey'], False)
if len(lines):
if len(rows):
conv_textview = self.conversation_textviews[jid]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment