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):
|
def delete_message(self, time):
|
||||||
elem = list(filter(lambda x: type(x) is TextMessage and x.get_data()[2] == time, self._corr))[0]
|
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))
|
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._unsaved_messages -= 1
|
||||||
self._corr.remove(elem)
|
self._corr.remove(elem)
|
||||||
|
self._message_getter.delete_one()
|
||||||
|
|
||||||
def mark_as_sent(self):
|
def mark_as_sent(self):
|
||||||
try:
|
try:
|
||||||
|
@ -159,20 +159,47 @@ class History:
|
|||||||
class MessageGetter:
|
class MessageGetter:
|
||||||
|
|
||||||
def __init__(self, name, tox_id):
|
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())
|
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 = 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;')
|
' ORDER BY unix_time DESC;')
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
self._db.close()
|
||||||
|
|
||||||
def get_one(self):
|
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):
|
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):
|
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):
|
def skip(self):
|
||||||
self._db.close()
|
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.tray = tray
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.initUI(tox)
|
self.initUI(tox)
|
||||||
|
self._saved = False
|
||||||
if settings.Settings.get_instance()['show_welcome_screen']:
|
if settings.Settings.get_instance()['show_welcome_screen']:
|
||||||
self.ws = WelcomeScreen()
|
self.ws = WelcomeScreen()
|
||||||
|
|
||||||
@ -262,6 +263,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
|||||||
self.messages.setGeometry(0, 0, 620, 310)
|
self.messages.setGeometry(0, 0, 620, 310)
|
||||||
self.messages.setObjectName("messages")
|
self.messages.setObjectName("messages")
|
||||||
self.messages.setSpacing(1)
|
self.messages.setSpacing(1)
|
||||||
|
|
||||||
self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
|
self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
|
||||||
self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
self.messages.focusOutEvent = lambda event: self.messages.clearSelection()
|
self.messages.focusOutEvent = lambda event: self.messages.clearSelection()
|
||||||
@ -332,15 +334,17 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
|||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
s = Settings.get_instance()
|
s = Settings.get_instance()
|
||||||
if not s['close_to_tray'] or s.closing:
|
if not s['close_to_tray'] or s.closing:
|
||||||
self.profile.save_history()
|
if not self._saved:
|
||||||
self.profile.close()
|
self._saved = True
|
||||||
s['x'] = self.geometry().x()
|
self.profile.save_history()
|
||||||
s['y'] = self.geometry().y()
|
self.profile.close()
|
||||||
s['width'] = self.width()
|
s['x'] = self.geometry().x()
|
||||||
s['height'] = self.height()
|
s['y'] = self.geometry().y()
|
||||||
s.save()
|
s['width'] = self.width()
|
||||||
QtGui.QApplication.closeAllWindows()
|
s['height'] = self.height()
|
||||||
event.accept()
|
s.save()
|
||||||
|
QtGui.QApplication.closeAllWindows()
|
||||||
|
event.accept()
|
||||||
elif QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
elif QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
||||||
event.ignore()
|
event.ignore()
|
||||||
self.hide()
|
self.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user