From 019165aeac8deb24425dee3c5350922bb122b43a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 4 Mar 2017 22:15:42 +0300 Subject: [PATCH] unsent files fix --- toxygen/friend.py | 10 ++++++++++ toxygen/history.py | 2 +- toxygen/profile.py | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/toxygen/friend.py b/toxygen/friend.py index 5871876..f560e5c 100644 --- a/toxygen/friend.py +++ b/toxygen/friend.py @@ -1,5 +1,6 @@ import contact from messages import * +import os class Friend(contact.Contact): @@ -37,6 +38,15 @@ class Friend(contact.Contact): def clear_unsent_files(self): self._corr = list(filter(lambda x: type(x) is not UnsentFile, self._corr)) + def remove_invalid_unsent_files(self): + def is_valid(message): + if type(message) is not UnsentFile: + return True + if message.get_data()[1] is not None: + return True + return os.path.exists(message.get_data()[0]) + self._corr = list(filter(is_valid, self._corr)) + def delete_one_unsent_file(self, time): self._corr = list(filter(lambda x: not (type(x) is UnsentFile and x.get_data()[2] == time), self._corr)) diff --git a/toxygen/history.py b/toxygen/history.py index eba0b8f..5eb8647 100644 --- a/toxygen/history.py +++ b/toxygen/history.py @@ -9,7 +9,7 @@ PAGE_SIZE = 42 TIMEOUT = 11 -SAVE_MESSAGES = 150 +SAVE_MESSAGES = 250 MESSAGE_OWNER = { 'ME': 0, diff --git a/toxygen/profile.py b/toxygen/profile.py index 84180dc..61d2b6e 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -219,6 +219,7 @@ class Profile(basecontact.BaseContact, Singleton): except: pass friend = self._contacts[value] + friend.remove_invalid_unsent_files() if self._active_friend != value: self._screen.messageEdit.setPlainText(friend.curr_text) self._active_friend = value @@ -329,6 +330,7 @@ class Profile(basecontact.BaseContact, Singleton): def send_files(self, friend_number): friend = self.get_friend_by_number(friend_number) + friend.remove_invalid_unsent_files() files = friend.get_unsent_files() try: for fl in files: