chat history fixes
This commit is contained in:
parent
fd722f4628
commit
4c6205cc39
@ -116,9 +116,10 @@ class Friend(contact.Contact):
|
||||
def delete_message(self, time):
|
||||
elem = list(filter(lambda x: type(x) is TextMessage and x.get_data()[2] == time, self._corr))[0]
|
||||
tmp = list(filter(lambda x: x.get_type() <= 1, self._corr))
|
||||
if elem in tmp[-self._unsaved_messages:]:
|
||||
if elem in tmp[-self._unsaved_messages:] and self._unsaved_messages:
|
||||
self._unsaved_messages -= 1
|
||||
self._corr.remove(elem)
|
||||
self._message_getter.delete_one()
|
||||
|
||||
def mark_as_sent(self):
|
||||
try:
|
||||
|
@ -159,20 +159,47 @@ class History:
|
||||
class MessageGetter:
|
||||
|
||||
def __init__(self, name, tox_id):
|
||||
self._count = 0
|
||||
self._name = name
|
||||
self._tox_id = tox_id
|
||||
self._db = self._cursor = None
|
||||
|
||||
def connect(self):
|
||||
chdir(settings.ProfileHelper.get_path())
|
||||
self._db = connect(name + '.hstr', timeout=TIMEOUT)
|
||||
self._db = connect(self._name + '.hstr', timeout=TIMEOUT)
|
||||
self._cursor = self._db.cursor()
|
||||
self._cursor.execute('SELECT message, owner, unix_time, message_type FROM id' + tox_id +
|
||||
self._cursor.execute('SELECT message, owner, unix_time, message_type FROM id' + self._tox_id +
|
||||
' ORDER BY unix_time DESC;')
|
||||
|
||||
def disconnect(self):
|
||||
self._db.close()
|
||||
|
||||
def get_one(self):
|
||||
return self._cursor.fetchone()
|
||||
self.connect()
|
||||
self.skip()
|
||||
data = self._cursor.fetchone()
|
||||
self._count += 1
|
||||
self.disconnect()
|
||||
return data
|
||||
|
||||
def get_all(self):
|
||||
return self._cursor.fetchall()
|
||||
self.connect()
|
||||
data = self._cursor.fetchall()
|
||||
self.disconnect()
|
||||
self._count = len(data)
|
||||
return data
|
||||
|
||||
def get(self, count):
|
||||
return self._cursor.fetchmany(count)
|
||||
self.connect()
|
||||
self.skip()
|
||||
data = self._cursor.fetchmany(count)
|
||||
self.disconnect()
|
||||
self._count += len(data)
|
||||
return data
|
||||
|
||||
def __del__(self):
|
||||
self._db.close()
|
||||
def skip(self):
|
||||
if self._count:
|
||||
self._cursor.fetchmany(self._count)
|
||||
|
||||
def delete_one(self):
|
||||
self._count -= 1
|
||||
|
@ -18,6 +18,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
||||
self.tray = tray
|
||||
self.setAcceptDrops(True)
|
||||
self.initUI(tox)
|
||||
self._saved = False
|
||||
if settings.Settings.get_instance()['show_welcome_screen']:
|
||||
self.ws = WelcomeScreen()
|
||||
|
||||
@ -262,6 +263,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
||||
self.messages.setGeometry(0, 0, 620, 310)
|
||||
self.messages.setObjectName("messages")
|
||||
self.messages.setSpacing(1)
|
||||
|
||||
self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
|
||||
self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.messages.focusOutEvent = lambda event: self.messages.clearSelection()
|
||||
@ -332,15 +334,17 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
||||
def closeEvent(self, event):
|
||||
s = Settings.get_instance()
|
||||
if not s['close_to_tray'] or s.closing:
|
||||
self.profile.save_history()
|
||||
self.profile.close()
|
||||
s['x'] = self.geometry().x()
|
||||
s['y'] = self.geometry().y()
|
||||
s['width'] = self.width()
|
||||
s['height'] = self.height()
|
||||
s.save()
|
||||
QtGui.QApplication.closeAllWindows()
|
||||
event.accept()
|
||||
if not self._saved:
|
||||
self._saved = True
|
||||
self.profile.save_history()
|
||||
self.profile.close()
|
||||
s['x'] = self.geometry().x()
|
||||
s['y'] = self.geometry().y()
|
||||
s['width'] = self.width()
|
||||
s['height'] = self.height()
|
||||
s.save()
|
||||
QtGui.QApplication.closeAllWindows()
|
||||
event.accept()
|
||||
elif QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
||||
event.ignore()
|
||||
self.hide()
|
||||
|
Loading…
Reference in New Issue
Block a user